Problem with spawnactor on multiplayer

I am making a building system for a multiplayer game. The only problem is that the server spawns the actor and it replicates to other clients, while if the client spawns the actor, it is visible to the client who spawned it but it ain’t visible on the other client and the server.


here this code is on the Player controller, so it should replicate on everything.

here it is on the charater, to place the block when building mode is on.

i did research of this for 1 week and all of the metods weren’t working. this game should be for my brothers birthday in 2 days so help would be apriecated.

Unfortunately, I have some troubles with image loading (not visible for me), but I guess you don’t mark your event as replicated.
image
Set this variable to “Run on Server” (and check “Reliable” check box under selection list) to execute this event always on Server. If you call Spawn event on Server, it will spawn actor to every player, but if you call Spawn only on Client, it will spawn actor only on Client.

When i do that the server can spawn the actor and it replicates, but, when i try to execute the event on the client it does not spawn the actor, neither it replicates to any client of the server

I managed to see your images and where is a GetPlayerCharacter usage. The point is if you call this on client, it’ll return a pawn of client player, but if you call it on server, even if event called from client, this function will always return host player pawn (player index 0 on server is always a host player).
Try to use GetOwningPlayerPawn function, it’ll return client’s pawn.

i could not find any node named “getowningplayer pawn”. the node that you’re taliking abuot is a ui only element, so i did this:
immagine

Sorry, I usually works with C++. In blueprints is called Get Controlled Pawn, and this can be found in Player Controller blueprint.

I tried, but it again doesnt work. again, the server can spawn the actor, but the client spawns it and it does not replicate to anything.

Can you show your blueprint code now? I don’t understand it’s condition.

In the first screenshot (On PlrController) change replication type of SpawnOnMulti to Multicast and left SpawnOnServer as Server.
Oh, wait, no. It’s better to move all spawn logic to SpawnOnServer event and completly remove SpawnOnMulti event. An actor will automaticly spawn on Clients if it spawns on Server.

Up until “SpawnOnServer” you are correct.
Then from here you should simply use the SpawnActor node and if the Actor you spawn is set to “Replicate” then other clients will have it spawned.

You should NEVER use Multicast for spawning replicated actors.

The server should always be in charge of spawning actors if you want those actors to be visible for other clients, the server is the authority. If you want a client to trigger the spawning of a replicated actor you need to send an RPC from that client to the server, the get the server to execute the spawning. Hope that helps.

1 Like

Hello Dear, how are you?

I solve this issue today. You need to check the “Replicates” check in the Actor that you want to spawn. Ex: BP_Actor01, must have “Replicates” check marked to can replicate his spawn to every client!