Managing Inventory
Discover how to manage inventory in a Rust-based game by enabling players to pick up, carry, and use items strategically. Learn to update item components for location and possession, handle player input for item collection, and display carried items on the HUD. This lesson helps you build a functional inventory system that enriches gameplay and user interaction.
We'll cover the following...
Items don’t always sit passively on the map, hoping someone will walk onto them. Unless we’re making a PacMan-style game, it also doesn’t make sense to have items activated when the player walks into them. Instead, let’s allow players to pick up items and carry them in their inventory until they’re needed. This adds strategy to the game, letting players decide when they want to use their precious items.
Items are entities, and they exist on the map because they have a Point component indicating their location. The entity rendering system query requires a Point to draw an item or display its tooltip. We can take advantage of the render system’s query structure by removing the Point component from an item when it’s picked up. The item no longer has a location on the map.
Picking an item up requires removing the Point component and adding a Carried component, with the stored Entity pointing at the entity carrying the item.
Add a new ...