A lot of the weapons and spells in the game have unique animations. When a player collects a new weapon, I will have to find a reference to this animation. I prefer there to be no visible delay when loading the animation off disk, so presently I am loading these at startup and storing references to them in a map, a pointer to which can be found in the GameInstance.
This feels a little hacky - and worse, it doesn’t work in multiplayer, because GameInstance obviously isn’t replicated.
I would love some tips/examples on how others are storing their animations after loading for later use.
I have received some examples of others who store and load animations on their items and/or characters - but this feels unsustainable. In a situation where that weapon will be instantiated 100s of times, I don’t want to load it that many times.
Where are people storing the pointers to their animations in code?
1
down vote
You could use something like the Flyweight Pattern to help you do this. Then each type of Being is really only loaded once (which can be done lazily as they’re needed), and then each Being instance just contains instance-specific variables such as position, speed, etc.
If that’s not enough of a savings, you could write an instance manager that has an API for requesting a reference-counted pointer to a Being. The reference object would notify the instance manager when it’s destructed. This would make it easy for the reference manager to marshal Beings to and from disk as needed.
Yeah, I’ve had a realisation that the instance doesn’t need to be replicated as it’s always the same data in every instance. So each client can load as they see fit. More of an issue for me is the AnimMontages not replicating, which is a serious problem right now.