Simple Set Actor Rotation RPC

I’m working on converting a single player RPG game to multiplayer for learning purposes. The starting point of this project I have is actually the ending point of the UnrealGaimeDev RPG tutorial. The goal is to learn how multiplayer works by doing. I’ve watched many tutorials, read the official documentation, but it doesn’t really stick until I start trying on my own. I’m stuck.

A basic outline:

I have a player controller. That player controller controls a ThirdPersonCharacter. That character can use a hotkey to fire a “begin spell cast” event on a skill actor (BP_MasterSkill). The particular skill is a projectile, which is a child class of the BP_MasterSkill class called BP_MissileSkill. The player controller initializes a call to the BP_MasterSkill class to begin casting a spell. This event is overridden by the child class BP_MissileSkill. Inside this evet we have:

When I test this, the server controlled pawn rotates fine. That rotation replicates properly to all clients who see the server character rotate. However, when a client runs this code it only rotates locally. The server and other clients do not see the rotation to that client’s character. I’m having trouble understanding why.

I tried doing a simple test by using the same sort of Server RPC - > Multicast RPC directly in the player controller to rotate the locally controlled character by a constant on key press. This works perfectly on all players! I even forgot to replicate the events, and it still worked.

Maybe someone more experienced than myself can help me understand what I’m missing? I appreciate any advice, or resources you recommend to understand what’s going on here better. Most tutorials I’ve seen so far are heavily simplified and not as practical as implementing multiplayer elements into an already fairly intricate RPG system.

I will not be a big help in terms of multiplayer but as far as I know - it’s better to create stuff from scratch instead of remaking existing Project as it will give you a ton of extra work

Especially if you’re learning - try something small, Multiplayer differs a lot from Single Player games

Also I see your Rotation Events are called only locally (probably the Multicast uses it)

You need a separate Event Chain for that purpose so:
Event (Local) - next event
Event (Server) - next event
Event (Multicast) - do the rotation event (rotation event should be Owning Client)

If I am wrong - please someone correct me

1 Like

I’m a little confused by the question by what is or isn’t working, but…

Maybe try making a rotator variable called “Rotation” and set it to Rep Notify. Set it right after “EventOnSpellCast” and plug it into “NewRotation”. Double click on the newly created variable to create an On Rep function. Pull off the execution pin in the function and use the logic to include the “FindLookAtRotation” from the previous event and set the “Rotation” variable in there. If this works you shouldn’t need it any longer in the event graph you used originally. You may need to create a replication condition that excludes certain actors in the variables default panel if it’s rotating the clients also (not sure without testing).

There also may be a possibility that you may need to run this on a timer using “SetTimerByEvent” the event being 'EventOnSpellCast" with a low duration as to prevent a stuttering effect when rotating. This might be because the rotation is being executed only once when you press the key, and the rotation doesn’t occur because it’s not replicating on tick like the server is to all clients. The client would need to update this replicated variable on a tick or timer for it to update with every little rotating increment for it to be visible.

I have no way of testing this in context to what you’re try to implement so I don’t know if this helps. Rotation is tricky to replicate especially vertical rotation as the engine doesn’t handle this kind of rotation by default. Anyway, good luck!

Calling server RPC only works for the owning client.
It works in player controller because all clients own their own player controller.
It would work in character or player state as well.
For everything else, it depends on how you set up ownership of the actor (the skill actor in this case). Try connecting the casting player to the Owner pin of the SpawnActor node when you spawn the skill actor.