I’m having trouble with the replication of an object that I want to spawn from a client and move it following the client’s mouse position.
The mouse location is found in the controller, then it should be sent to the spawed tile. The replication works from server to client, but not the other way around.
From the debugging, it seems like on the client the mouse position is not being updated on the tile.
I’ve tried both multicast and run on server but none worked.
I feel quite stuck, so if anyone can point me in the right direction I would be really grate.
Hi, I’m not quite sure I understand what you’re trying to do =)
(1) If you spawn an actor clientside, then that actor will only exist on that client. The server and other clients will never know about it.
If you want the server and clients to know about an actor, then you would need to make that actor replicating, and spawn it on the server.
(2) Replication works only one way: From the server to the clients. If the client wants to tell the server something, then you would use a “RunOnServer” Remote Procudeure Call RPC (client asking the server to execute this event). The only client that can call “RunOnServer” RPCs, is the client that owns this actor. If any other client tries it, nothing will happen.
From the debugging, it seems like on
the client the mouse position is not
being updated on the tile. I’ve tried
both multicast and run on server but
none worked.
If you spawned that tile on the client, then it won’t exist on the server, therefore if you try to send a reference of that tile to the server via “RunOnServer”, then it will be None on the server.
Hi! Thanks for the reply!
The spawning seems to work correctly. The tile spawned when clicking on the client is spawned on the server as well (in the right position) but then it lerps towards 0,0,0, because the Mouse Location variable doesn’t seem to get updated, neither on the server nor on the client.
If I spawn a tile on the server though, it moves correctly both there and on the client.
All this code and the one on the other images happen on the same blueprint, which is a subclass of the Controller class and doesn’t have Replicates enabled.
If I spawn a tile on the server
though, it moves correctly both there
and on the client.
From the two images you have shown above you always spawn it on the server, never on the client (“RunOnServer” events will execute on the server).
I can’t tell you want is wrong. But since it works when the server is doing it, then that would mean you have a problem with replication / client to server communication somewhere. I would do some prints and compare the printed values between doing it on the server and on the client, to try to pin it down.
I’m having a problem with object references not getting passed from the client to the server on event calls. Try printing the display name on the server and see if the object reference is actually getting passed. Doesn’t solve your problem (I haven’t found a solution yet), but may help explain the source.