Storing and loading Animation references in C++

I’m making a multiplayer RPG.

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?

Game instance seems fine. That’s where you keep persistent data.

  • Make an “AnimationManager” class with “GetAnimationByName()” and keep an instance of it in the GameInstance.
  • Store Animation-to-Name pairs in a Map.
  • Have your objects GetAnimationByName() on BeginPlay() or wherever.

Seems pretty straightforward and avoids loading animations multiple times or during the game.

Yeah, that’s essentially precisely the way I do it now, almost exactly.

The issue is - GameInstance isn’t replicated. So it doesn’t work in multiplayer.

Anyone had any success implementing a similar approach that works in multiplayer?

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.

I’m not sure what you’re getting at, Ethan. Could you contextualise it?

Why does it matter if the Instance isn’t replicated? If all the clients have the information, just build it at load time.

  • Client Loads
  • During load, Client builds the Animation Map (all possibilities)
  • Client then has all the info no matter what weapon a user has and dynamically grabs the animations 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.

Thanks for the help, all.