Help updating an actor for each client?

I’ll keep trying to figure it out. Thank you for your help so far!

I couldn’t think of any reason why this would be happening so at this point I would assume it’s some weird setting that is causing the issue.

First make sure you’re not doing 2 separate Standalone sessions. Be sure that you are running a listen server.

image

Then I would create a new PlayerController class and create a really simple function like what I did in blueprints above, (but do it in C++) and see if you’re able to get the multicast to execute on both server and client.

If it still doesnt work, I would assume it’s something with my project, then i would create a new project, and then try to get a simple function that communicates like it should

1 Like

I did what you suggested to test if it was a problem with the whole project, and I got the same result as before: only one client gets the function. Do you know what could be causing this? Maybe another class? I have a custom gamemode, HUD, game state, and player state class, and the default pawn is set to “none” because the player doesn’t have an in-game character that they control.

I just realized that PlayerController might be causing the issue, because clients only have their own PlayerController, but not the other PlayerControllers in the game, so it can’t multicast because clients don’t have any PlayerControllers on their machine except their own.

You will have to do this logic on your Pawn class instead.

I googled “ue4 multicast playercontroller” and found a bunch of stuff, if you’re interested, you should read through some of it.
https://answers.unrealengine.com/questions/818293/calling-multicast-function-from-playercontroller-p.html

1 Like

You should never use multicast for updating state on clients. Multicast should only be used for cosmetics that are only relevant in the given moment like particle effects etc.

Input should be handled on the PlayerController and make Server RPC function calls on the PlayerController. From there the server should call the necessary functions that will Set replicated variables as needed on Replicated Actors that will then be seen by all players.

1 Like

You will have to do this logic on your Pawn class instead.

Ah, I see! So I could move the MovePiece_Client into a player pawn class? Since the only variables, it’s using are passed as parameters, it should be really easy to migrate it. Then I could just change the player controller’s MovePiece_Server function to call the multicast function that’s now inside of the pawn the controller it’s possessing?

Yea, it might be a pain moving all that stuff, but you just can’t call multicast functions on PlayerController.

Like GarnerP57 said, you could use all replicated variables and use OnRep_ functions to execute code when a replicated variable changes, but you would probably have to change a lot of what you’ve done already.

Here’s a thread that explains the difference between OnRep and Multicast.

However I found the OnRep stuff to be a giant pain in the butt for a bunch of different reasons.

1 Like

What reasons?
Replicated variables and RPC’s work together, RPC’s used for Events and Replicated variables for State. If you only use RPC’s you are going to have a lot of overhead and get out of sync eventually.

1 Like

I just started programming a few years ago and I started on Unreal Engine.

I remember the documentation was really hard to find, and hard to understand(as a new programmer) and sometimes the OnRep functions wouldn’t execute when I thought they would. Eventually I found out that it won’t replicate the same value twice, but by that point I just wanted to get it working and again, I couldn’t find documentation or examples anywhere.

I guess it wasn’t so bad. A better way to say it would be : it was just easier to use RPC’s because you don’t need much documentation to understand how to use them.

1 Like

So doing the stuff that I described should work? I.e. creating a new pawn class and using the parameters as variables?

yes, that should work

1 Like

Great, I’ll try it out!

It worked! :smiley: Thank you so much for the help!!

1 Like

Hi, so sorry to unbury this topic, but it turns out that this actually didn’t fix it. The update function still only runs on the server and the client, and the reason I think this is is because the second player controller doesn’t possess the second pawn. They both exist in the world outliner, but for some reason, the player controller can’t find the pawn GetAllActorsOfClass() returns nothing when called in it.

Yea PlayerControllers are weird, you can only call Possess on the server. If you hover your mouse over the possess node, you can get a little info about it. Basically, you’re going to make a server RPC with your client’s PlayerController as the parameter.

So I’ll need to manually tell the server to tell each player controller to possess their respective pawn at the beginning of the game, and I can do that inside of a server function? Should each controller be looking for a pawn with a matching index and possess it?

Edit: spelling