Tutorial - Entity storage
Entity Storage is basically a script that can be attached (via script during runtime) attached to one or more entities.
This comes in very handy especially when you have entities that have the same behavior and set of variables. Even more so when you’re spawning entities from your script.
- This is a nice example of how you can use Entity Storage. We want to randomly create target dummies which player can destroy by shooting at them.
- We spawn the target dummies from within the Event Listener script. The first one is spawned as the game starts, the next one whenever the Listner detects the current dummy getting “killed”.
- The dummies are spawned at randomly selected Reference Points in the scene and they have Entity Storage attached. This Entity Storage contains variables - namely how many points of damage it takes to kill this entity. Every time a dummy is spawned this value is randomly set within a given range - so every dummy needs to receive a different amount of damage before it is destroyed.
- Even though in this example we only have one active target dummy at a time, nothing is stopping you from having many object with attached Entity Storages at the same time.
- Also note that the Event Listener detects only target dummies getting killed - that is because it is set to detected only objects with a certain label - the one we’re attaching to each target dummy as we spawn it.