Updating a replicated variable from client to server

I’m sure this is simple and I apologise in advance. I’m very new to all this and I’ve spent hours fiddling, googling, and asking ChatGPT and I still can’t get my head around it.

So I’ve got a directional light blueprint called BP_Sun. I increase pitch by 0.1 every tick and have it replicated so all clients get a nice day night cycle. Easy stuff!

Now I want players to be able to increase and decrease the speed of the day night cycle. So I swap that 0.1 out for a replicated variable called SunSpeed and make it editable, then get a reference to it in my player character.

Now in my player character blueprint, when the character interacts with a particular button, the SunSpeed should go up or down. Unfortunately, I can only get it working when the server client(listen server?) interacts with it. When a standard client interacts with it, a print string shows that the SunSpeed updates inside the player character blueprint, but does not update inside the BP_Sun blueprint.

I’ve tried every variation of “Run on Server” “Run on Owning Client” and “Multicast” with the custom events, and it doen’t work.

I am clearly missing something. Could anyone point me in the right direction?

Thanks!

RunOnServer is the correct one with the sun speed being on RepNotify BUT you need ownership to call RunOnServer so you may need to call the function from your PlayerController

This worked! Thank you! I am still not sure if I understand ownership. I assumed if the client has ownership of the PlayerController, then it also has ownership of the Pawn?

usually yes, you can set owner on spawn but its probably best to assume the server owns everything except controller and pawn, playerstate too i think, basically the player should own what it wants to directly control

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.