error getting variable value on server side

Hello guys how are you doing? I have a question I want the server to know what is the value of the variable “attack anim1” which obtains its value from a struct. I replicated the variable and also RPCed the function where it gets the value. What am I doing wrong or what can I do to fix it? thank you so much.

You’ll probably need to play that anim montage on your rpc multicast event. I would put it behind the “animontageclient” multicast event.

Which struct ? A client-side struct ?
If so, the server doesn’t have that struct so you need to either replicate the struct to server, or replicate variable to server.
Variable replication only works from server to client, so setting the variable value on client will not replicate it to server. You need to use RPC for client-to-server replication.
For example, add a parameter to the animmontageserver RPC so you can pass the value of AttackAnim1 from client to server, then assign the variable value on server, then it will replicate to other clients.

The function that contains the play anim montage already has replication, I just need to make the server find out the value of the variable that contains the reference to the animation that is going to be executed, which comes out of a struct of the sword

The struct has the weapon that is equipped in that struct, there are the values ​​such as the position of the sword, the type of magic it uses, the animations, etc… How can I replicate or inform the server of the content of that struct?

If you want the other players to see information about the weapon, no matter the time they logon you would probably have to set it via a RepNotifty on a variable with the information.

Though I think that you are putting too much responsibility on the character looking at all of the pins you are setting from the struct.

1 Like

I see… It appears that your are having issues with the struct not replicating in the first case.

You can run a “Run On Owning Client” event from your player controller and get your struct from wherever you are setting it (presumably from somewhere persistent such as the game instance) and the from there, pass it through to another server event possibly on your character and into a multicast event and the set those variables there.

While you were at it, it would be best to set it up as a rep notify so that it’ll replicate for other circumstances that are relevant such as late joining players or players that are out of the players relevancy when executing them.

So it would go something like:

In the character have a server event that passes an empty struct variable to a multicast event and sets an OnRep struct variable there. Inside the RepNotify variable’s function get the struct RepNotify variable and set new variables in the character inside that function with the appropriate information to be replicated. Also mark those new variables on the character to replicate as well.

Call this server event from the player controller bp off begin play or your spawning logic or somewhere appropriate to you.

Such as:

RunOnOwningClientEvent> Cast to your game instance> Get your struct variable from the appropriate game instance inside the player controller. Cast to your character and call the server event in the character above and pass that struct variable into that server event on the character from inside the player controller. These variables shouldn’t need to be marked as replicated here at this point in the player controller or game instance as they will be once they reach the character’s server event.

This should set you up to run around with all the stuff replicating for anyone everywhere and execute all of your previous events from the original post.

edit: The setup above would look nearly identical to your latest screenshot except it would be executing from inside the rep notify function and the struct that you are getting inside there would be set from the multicast event so you wouldn’t need to cast to your character as it would be good to be executing it from the character also like mentioned above(if that makes sense).

1 Like

Thank you very much for your answer and your time, I’m sorry for the inconvenience but could you record a short video for me about the example you gave me or if you have any video or documentation where I can see your answer better exemplified? thank you so much