Download

Delay in Newobject info from server to clients

I been having some issues with the delay in NewObject creation info from the server to the clients, in which i need to set the variables for the NewObject.

basic flow of info would be:

  • NewObject BoxComponent (RPC)
  • SetTimer to functionA (NetMulticast)
  • functionA - do something to the variable of the newly created BoxComponent.

The server side works fine with variables. But the problem is i cant be sure when the info will reach the clients (from server) for me to assign the variables to the BoxComponent.

i did a “hack” in use of the tick function to solve this issue but that doesnt seem to be the right way of doing things.

I knew that custom created c++ class with its own constructor can solve the assigning values right from the start. But let us say i am more interested in dealing with the delays from the server to the clients and the proper way of doing things.

Can someone please share their expertise?

Wait so are you creating a BoxComponent and sending its pointer as an argument to an RPC? Or are you sending an RPC so that a default BoxComponent is created by the receiving end and then trying to set its values remotely? Either way that’s probably the wrong way to go about it, since BoxComponents are required to be inside actors to function properly anyway there’s no point separating them from an actor. You should probably just set up a replicated array of BoxComponent pointers and let actor replication handle it for you. So what exactly are you trying to achieve though? For example are you having a building game where clients want to attach their blocks to their building and have that be replicated to everyone else?

I am creating them dynamically(during runtime) instead of doing it statically(in constructor) in a character based class. I am basically still learning the correct way of doing things for networking.

So you are saying is i need to create them in the client? But wont the server and the other clients not get the creation if it wasnt done thru RPC? So how to setup a replicated array of BoxComponent pointers and let actor replication handle it for me?

I have been trying network stuffs for close to three weeks and it is mighty confusing especially with the current documentations.

Actually don’t worry about the array, I forgot that UE4 already keeps track of them. This page tells you how replication works in general, and this one tells you how to replicate components specifically.

The server controls everything and automatically makes sure everyone has the same data, so your clients can only ask the server to do something for them (like spawn a BoxComponent on an actor).

Whenever a client wants to create a BoxComponent they send an RPC to the server asking it to create a BoxComponent for them with the right properties like box size. The server creates a BoxComponent and calls SetIsReplicated(true) on the new component. Now the server will automatically replicate the BoxComponent to everyone. If you want to change stuff on the BoxComponent, the server has to do it. If a client wants to change the variables of the box later on, they need to send an RPC to the server with the new variables and have the server change the box for them.

Don’t send a ‘CreateBoxComponent()’ RPC and then a ‘SetBoxVariables(x,y,z)’ RPC right after to set its variables, send the initial variables as arguments to the create RPC like CreateBoxComponent(x,y,z).