Hello awesome comunity. How do I save additional per instance data for a hierarchical instanced static mesh?
I have a game that simulates an ecosystem and am running into a problem with the hierarchical instanced static mesh. For preformance reasons, I am using multiple HISM objects to track plants (which spawn and get eaten etc). I need to store additional data for each mesh. Using objects in a lookup dictionary results in indexing problems - no matter what I try I can’t keep the indices matched. So I am looking at storing data in the material. I can easily add custom data into a material via the ‘set custom data value’ command but how do I retrieve these values?
As example, a plant instance needs to keep track of its spawn time for life span and size, the amount of nutrition it provides, its seeding cycle etc. so I need a fair amount of additional data for each mesh. I also need to be able to periodically loop through the HISM to update the size of the plants as they grow. I have all the logic in place and working but can’t get around the indexing problems as plants get eaten.
In BPs that’d be a no-no. In C++ perhaps? Google confirms this exists:
GetCustomDataValueOnInstance
But I’ve never seen it done or even documented…
Besides the above:
so I need a fair amount of additional data for each mesh
The official docs state one can store 32 floats, which is not true - at least it wasn’t in 4.27. The actual number is either 16 or 18 - last time I tested it. Which is still plenty but it’s just floats.
How I do it:
use the Tmap with key being the index and enjoy any data type via a struct
never remove instances
instead, move them where they can’t bother you; flag its hasBeenEaten map data appropriately
bunny eats a carrot? That carrot now lives 5000 uus underground where no sensible bunny should go
to regrow it, reuse one of the eaten carrot instances that lives underground
at some point you’ll need to save it all - that’d be the time to trim the HISMc and repopulate the map from scratch
Think of this as of object pooling. The key is to not remove any HISM instances.
Thanks for the reply, it appears that aside from the ‘plant purgetory’ with reincarnation which I don’t really like there is no viable solution. I have the same problem with seeds which disappear and spawn plants. If I need relocate everything and store a reincarnation array (souls awaiting liberation from hell and rebirth into the material world) to recycle things, Hell is going to be pretty crowded. Still, thanks for the reply - I guess I’ll start coding demigod Hades / Yamaraj…
I’ve done pretty extensive research and can’t seem to find any more elegant solution. If anyone knows of one, please share…