Replicate Possess Actor on Client

Hey, how can I possess an Actor that is already spawned on the level, on the client-side?

Server-side I can possess without problems, but when I try on the client, I can’t possess the Actors at all. What am I missing?

Thanks.

Possess is a server side only event (you see on the little icon next to the node). if you want that called from client you need to wrap it in a server-RPC (create a new event, set it to run on server, call that from your client controller or any client owned actor) and maybe pass the clients player controller as a variable to that event (most of the time getting the one pc on the client is easier thant finding the right one on the server side)

Hi, yes I’ve tried creating a RunOnServer Event, something like this:

But now it runs on Server but on Client it doesn’t even Print String.

I guess you’re right, I need to pass the right player controller variable on network, but I have no idea what it is :confused:

Run on server first but replicate to client by calling run on owning client, not multicast.

It prints but doesn’t possess on client, here’s how I defined it:

You don’t need Multicast or run on owning Client for that. Create a Event Run on Server with an Input variable of Player Controller, in Client call getPlayerController and Feed that as a Parameter to calling your new event. Best place to get owning Player Controller ist pawn, or inside your Player Controller use SELF

Ok so I’m still having trouble possessing pawns on client, I’ve changed a couple of things:

  • On server, on the Level Blueprint I have 2 actors spawned, which when I press the Tab key, it Possesses/Unpossesses one another (this part works well)

  • Then, on Game Mode Blueprint, I set the event OnPostLogin to create an additional Actor (so there are 2 Pawns on client)

So now I have 4 actors overall, 2 server-side and 2 client-side, problem is I can’t Possess/Unpossess when pressing Tab key on client-side, but they both Print String.

So server-side I have 2 Actors placed in world whereas on client-side the 2 Actors are created OnPostLogin and come from a PlayerStart.

I think I’m not getting the client-side PlayerController right as it returns None.

Any help appreciated, thanks.

do you have basic ue networking knowledge? to sum it up: spawn your actors (except of ui and cosmetics like vfx,sfx) on the server, not on the client. the gamemode lives ONLY on the server. if you want to interact with it from client, you need a server rpc. a server rpc can only be triggered by an actor the client owns (the Playercontroller is one of that actors for sure). a multicast can only be triggered by the server (or via a server rpc). when you spawn an actor which is set to be replicated on the serverside thats all you have to do to appear that actor on all connected clients. thats it in short :wink:

ah, and try to avoid levelBP - most things people do in there is the wrong place…

if you tell more what’s your goal I can maybe put something together for you or give you a tip what to do. As far as I understand you want two pawns being spawned on gamestart by each player, and whenever a client presses TAB you want to switch between these two? (like a mini team of two characters / player)?

I’m learning how networking works, so far I don’t have any problems with replicating character movement and damage, but the Possess is breaking me…

Yes, I have 2 actors spawned on the map that I can switch between on Player 0 when pressing Tab, which are controlled by the server-side, then, on a PlayerStart (which I called NetworkPlayerStart) I possess the default character plus I spawn a second Actor so I can switch to it when pressing Tab on the client > this is the part that I can’t wrap my head around

Thanks on your note about level BP, but that’s the only way I know how to get an Actor Reference from the map itself.

See here:

add a replicated var TeamColor and TeamPC (linear color/controller) with checked exposeOnSpawn and InstanceEditable to your PlayerCharacter to test it.

event switchPawnOnServer in PC needs to be “runOnServer” rpc

so the basic idea was in the GM to compare the owner to find the pawns which belong to that player…but I guess it’s a UE bug that the getOwner returns null after the first switches. After possessing it it shows up - strange - this is why I added an additional variable for storing the PlayerController.

have fun :slight_smile:

Appreciate the help, I’ll look into it and then check back here. Thanks.

Hey man, you the real mvp, everything is working as expected now - thanks once again, not everyone takes their time to help others :slight_smile:

I’ve dumped the 2 Actors that I had spawned on the level and only use PlayerStarts, so to find which PlayerStart corresponds to each Player, I’ve overriden the ChoosePlayerStart function too:

Your Welcome :wink: thats good