Download

Replicating Variable Issues

I’m having a real hard time getting familiar with how UE4 replicates stuff. I understand the basic concept for client/server interaction and not to trust the client - what I don’t understand is how to replicate stuff from a client to a server in order for the other clients to see the same update.

For example I have this scenario I’m playing around with, basically one player will assume the role as a commander of sorts*(those who played Savage 2 will get the idea)* and can place structures to be built. Other players on the same team will assume a FPS/TPS role instead and will work for the commander - building stuff, fighting and so on.

So far I’ve got most of it working, the listen server assumes the role of being the commander*(plan is for this to be available for everyone; not only the host but limited to one player per team). I have 2 testing blueprints for an object, one which acts as the preview - it has no collision and shows a glowing wireframe of the object. And one which is the “actual” object itself, this actor is spawned when the commander left-clicks(spawned via GameMode)* and the preview actor is destroyed.

To keep things sensical, those are the actors;
BP_TestBuilding_Preview (This is just a dummy. No collision; set to replicate and replicates movement - movement is seen as intended on both server and clients)
BP_TestBuilding (This actor is spawned when a location is chosen; it uses the last know location of the preview actor. Set as replicated; spawns properly on both server and clients; Has a replicated float variable "buildProgress")

BP_TestBuilding creates a dynamic material instance upon spawn, which has a scalar parameter which I want to increase whenever the object is hit by a linetrace from a client. Therefore the replicated float variable.

However, I simply can not figure out how to update this material for the server and all clients, I can only ever have it update on the client firing the gun. This is whether I make a custom event that is Multicast or Run on Server - it makes no difference.

What I’ve tried is breaking the hit result of my line trace and checking the actor to make sure it’s a child of BP_TestBuilding; if true, it will cast to BP_TestBuilding and update the buildProgress variable. Once that variable has been increased, it will go ahead and set the scalar parameter for the dynamic material instance.

How would I go about to replicate this across the board? It will only ever work for the client shooting the actor. I’ve tried using RepNotify and updating the material instance via that, but it yielded the same results.

Sounds like you dont change the float on the server.
What is your setup for this? Could you post a picture?

Ugh, just got it working after reading your reply. I was trying to create a server-side event inside BP_TestBuilding itself and do it from there, I believe that’s what was causing the issue. So instead I made a custom event inside the character where the linetrace is made and set it to run on server.

Doing this, however, I’d need to create an event for every build-able object. Any ideas on another approach to keep it a bit tidier?

Knew it :smiley:
The problem is you need to be the owner of an actor to execute server events on him.
You could set yourself as owner (on the server) after you have checked that you can/want to run server events on the actor.
Keep in mind you take someones rights and this could affect your gameplay.

Edit: Keep using RepNotify in your case, otherwise you will have problems again in the future!