Step-by-Step "Tutorial" for client-to-server Replication needed

Hello,

since nobody seems to answer my previous question, I go one step back and ask for a more simple solution to a problem. I got more understanding in my previous approaches, but I still cant really figure out the right way to accomblish it.

So what would help me now would be a really small step by step tutorial for a variable replication from client to server.

All that I need would be a simple setup like e.g. the following:

Bool Variable (test) = false

Begin Play → Delay → Set to true (so far I can do it of course :D)

And then exactly what I should click to make the state of the variable change on the server too. What event/function to create, name them (example), how to call.

I know, this is a very special request for the answer hub, but the asked issue is pretty simple I guess, so it would help me a ton, if somebody could provide me with a step by step and some pictures maybe.

Thanks so much!

In the blueprint editor create a new bool variable and in the bottom left you will see a dropdown called replication, set it to replicated and you are done.

Short tutorial on the unreal blog as well.

Hope this helps ^^

Unfortunately this only replicates from server to client. I need it the other way around and read, that this is a little more complex. With rpc to call and such. I need help there, but thanks :)¡

Whats the context of this question? What thing sets the bool and why should the server use the client value?

Normaly you would make a replicated function. Thats a custom event. You can set the replicate to “Run on Server”.

This is called by a client and runs on the server. So you could make an input for this event (bool) and pass the bool. Use a “authority” node to make sure the client only calls it. Then on the server side of the event, use the variable you passed to set the variable serverside.

A custom event always has a red node and a blue node. If you create the event, you get the red node. Here you set the replicate option and add inputs. Now you can search for the event like every other node and use this second node (" blue") to call the event. So the begin play goes into a delay node then into a athority node, then on " is authority" into a set node that sets the replicated bool directly and on the client exec you take the custom event and mark the bool input with true. At the other end of the event you take the bool and again set the bool.

That should be all. Cant give you pictures because im on phone.

For the context thing,

I have 3 UMG Buttons, which are supposed to select one out of three players.

The basic Idea is select one, let the selected one be spawned by the server and then possess it on client side.

Now I cannot get a UMG click event to do anything on the server, so the Idea was to set a boolean on the server via click and then let the server do the spawning based on the bool.

But I cant get the bool set on server side.

I read through your comment, and this is more or less the info I gathered in all the forums and answers, but I just cant get it to work. Thats why I would have appreciated a pictured step by step for just the boolean, cause the rest I could manage…

Okay here is my latest progress. I tried to follow your instructions, but I am still struck.

Basically, on 1.) the Blue “Replicated Mage Spawn” gets called via a button pressed through UMG in another blueprint. This works for sure. But after that I am stuck. I have the manuall created Bool laid out and I created an input bool in the event. I marked them on the screen accordingly. Maybe you could do a small paintover? :slight_smile:

Okay I got the theoretical part all figured out. I know how to connect all the dots to make the magic happen.

BUT

My RPC gets not called, because I am not the owner apparantly.

I have selected to start with Default Pawn to “None” so at Begin Play I am basically “nothing.”

The Blueprint above is on a actor called spawner, which is placed inside the level.

How would I accomblish to “own” the spawner blueprint, while being nobody so to say?

P.s. Since I do not know how this question gets updated in the answer hub, i will start a seperate question soon.

Did you replicate the variable?

how would you replicate a float from a client to the server and any other clients? when I use a custom event set to “run on server” the float just stays at its default value no matter what, I have tried putting the float in as an input in the custom event but that comes through as zero every time or if I plug it strait into what it is meant to be doing inside the custom event then it uses the default value but doesn’t listen to what the client is doing.

Is the number 0 before entering the event?

What class are you working in? Not all classes allow Run on Server.

yes I did…

I am getting the relative rotation of the camera arm and braking that into 3 floats, I then set two variables with the pitch and yaw, these variables power the aiming offset in my animation blueprint. The aim offset points the characters head (the character is a dragon) in the direction you are aiming the camera.

If I don’t use custom events it works perfectly on the client but other players don’t see it, I have tried setting the variable in a custom event set to “run on server” and then the server can see the aim offset working but all clients see it aiming north (world x or something I think) rather than in the direction the camera is facing.

Can you explain what you are trying to do? Simply set a float variable on all clients? Like what… HP? Score?

It’s easy. You need to run a custom event on server, then from the server run a multicast event with will set the variable on all clients.

I just tried to add multiplayer aim offset and I got it to work… Care to show me your blueprints to see if I can help?

Maybe you should make a new question regarding this

So here is a picture of the bit to do with the aim offset, I’m setting the rotation of “look Direction” every frame I don’t replicate that (when I’ve tried it stops working altogether)
The event called update look angle is set to “run on server” I have tried putting it through a has authority node as well but that makes no difference. any ideas, if you need to see the whole thing I can send it later.

Okay, I think I see the problem.

Add a branch right after Look event, and use “Is Locally Controlled” as the condition. If true, then Update Look Angle.

Let me know if it works

Excellent! yeas it works :slight_smile: thankyou