Is there a way to replicate a variable during construction/spawnactor like location and rotation?

I have an animation blueprint with the first state called spawning. In this spawning state, there are many anims and it picks (uses blend poses) the anim based on a variable enum. The variable enum is set during “Event blueprint initialize Animation” by picking the value out of the pawn/character owner. If I instantiate the character in the editor by dragging the character blueprint to the level and set the varible enum in the details panel and press play then the character plays the initial/spawning animation perfectly on both the client and server.

But we have spawners in c++ that calls spawn actor on that character blueprint. The spawner sets this enum on the character. On the server, the character spawns in and plays the animation just fine but on the client it does not play the same animation. It seems the variable on the character replicated too late on the client.

My question is in two parts:

  1. Is there a way in c++ to spawn an actor, set a member variable to be replicated before replication so that when it appears on the client the variable has been set just like location?

  2. If not then is the way I described setting an initial animation the correct way to do it? Is there a better way?

thanks

If your variable is on Character then there is no way you can replicate before you can spawn, my suggestion is you replicate your variable is on one actor for example PlayerState, make sure it replicate to the client then you can spawn the character on server after that and on client in begin play just get the variable from that actor and set your initial state.

I use it for my Character Class which have difference Mesh for same Character, so at start when player choose the class, i save in PlayerState and replicate it, then when spawn character i just take the class in PlayerState and set the correct mesh for character.

Gotcha. Its not for the player but for AI. But I see what you are getting at. If I understand it correctly, I can replicate the parameters in the spawner class we made and when we spawn on the client then the AI can pull the params from there.

yeah make sure the param is always set and replicate back before you spawn your character.