How to replicate an on clicked event from a widget to the client?

Ok so basically i have a button on my game. When the player clicks the button it then spawns the player and takes control of the pawn so that i can move around etc. The problem i have is this functionality only works on the server side and not the client side. It spawns the player ok but it doesn’t posses the player. i figured i could solve this problem by having a custom event that is replicated and then just getting the on clicked event to call this custom event from the widget but for some reason this is not possible? so how would i get it to work so that when i click the button on the widget it spawns and posesess on both the client and the server? or is the on clicked events in the widget set up wrong?? i noticed that the posess function though states it will only execute on the server so is this the problem ?? if so how would i get it to work on the client would i need some other module??

here is my widget events

Here is the server side image . as you can see after i have clicked the button it has spawned the character and i have taken control and can walk around etc

Now here is the view from the client side . as you can see it has spawned the second character, ( although for some reason it has spawned him with his feet in the ground which is wierd). But unlike the server version it hasnt taken control of the pawn and i am unable to move around or do anything

i think what i need to do is move all this code from the widget and have it in a custom event that is replicated in my level blueprint like this

so it will effectively do the same thing, but how would i get the widget to call this custom event when the button is pressed. or am i going about this all completely wrong
Hope you guys can help clear this up as im a complete noob to unreal

thanks for youre time

No, don’t use the LevelBlueprint for this. You are correct in thinking that the Possess needs to happen on the Server and that the Client needs a replicated Event.

Do the following: Take your PlayerController for this. You need “NetOwnerShip” to call RunOnServer functions, so the PlayerController is perfect for this (and also
the PlayerController is one you need to possess, seems to fit, right? (: ). In your PlayerController, create a CustomEvent. Set it to “RunOnServer”. In this Event,
spawn the Player and call “Possess” on it.

Now in your Widget, when you press the Button, get the PlayerController (0) and cast it to your CustomPlayerController Blueprint. Then Call the RunOnServer Event
you just created.



And this is enough. The Client will get the Control with that (:

Hi thanks for the quick reply. Will have a go tonight when I get in from work and let you know how I got on. Cheers

Take your time mate (: Feel free to ask me if something is unclear!

yep just made those changes and it worked fine Thanks a lot mate. only problem is now it causes a bug if two people try to spawn in at the same time as they are spawning in the same location. guess i need to figure out a way to create multiple spawn locations and then get each person that connects to spawn in there own spawn spot.

God programming is a cruel mistress, don’t even get time to enjoy you’re victory before the next problem rears it’s head :frowning: lol