How to Spawn the actor on all clients including the Server

Good evening, I would like to know how I can spawn an actor on all clients in the network, including the server. Example: I called this event on Client 1, and only client 1 spawned the actor. The server can see the spawned actor, but on the server was not spawned. If I execute the event on the server, only the server will spawn the actor and the client will be able to see it too but the actor will not be spawned on client.

I’ve been trying for days to figure out how this works, and where my error is in the code, but so far I haven’t been able to understand it. Thank you very much if anyone can help.

My Custom Event

After run the Event in Client 1

My actor settings

Example
Client 5 Run Event to Spawn Actor in all Clients including on the Server

Like so…

When your second Run on server fires “Spawn Actor” it is done so as all clients,

All clients try to fire the custom event “Spawn Actor” which much be Run as server… so all clients except the one that is the server drop the RPC

Always useful when figuring out “How to multiplayer”/Replicate

1 Like

I’m not really sure MC_Spawn is needed. Just the call on the server should do the trick - ROS_Spawn to spawn the actor. Just make sure the actors you spawn are replicated and that you call the server function from a BP that is owned by the client. (i.e. from the character you control)

P.S.
@Nightwolf suggestion might also work but you should relay on replication instead of multicast events whenever possible.

1 Like

Multicast is not needed for ANYTHING that is initially spawned by the server and is set to replicate.

Input → RPC Server
Server → Spawn Actor that replicates

Done.


Additional Info…

Collision Handling Override :: Try to adjust Location, But always Spawn

Get Actor Location as the Spawn Transform Location is going to spawn the actor inside the Capsule Component. Actor Location of the character class is Always the center (X,Y,Z) of the capsule component.

Default will spawn it inside the characters pelvis area, then depenetration is going to push the character class out of its collision.

1 Like

Thanks you, but I tried this method but only 1 actor is spawned, the message is replicated normally but the actor is not

Thank you, this method works perfectly but only 1 actor is spawned, I need it to be spawned on all clients in the network, look in image

I need this result, spawn actor in all clients in same time including the server
I need this:

Thank you, this method works but for only 1 actor, see the example for what I need

The result is

I need this result: multiple spawn actor in all clients in same time

Here i calls event in server and the actor is spawned only in server, i need that spawn in all
Animated gif
teste 00_00_00-00_00_30

its your TestActor that you need set to replicates

1 Like

My actor settings is:

i saw that but is that specifically the actor you’re trying to spawn?

1 Like

Yes, it is this actor, but when calling the event I would like this same actor to be spawned in all clients of the network at the same time.

Note that when I call the event the actor is spawned only on the client/server that called the event
teste 00_00_00-00_00_30

I need this result

It would be something like if the client that called the event executed this call to “spawn” the actor in the other clients of the network too, like remote command, but I don’t know how to do it

well Rev and dZh0 gave you the correct setup,

you said its spawning on server correctly and IF its spawning on server and set to replicate it will spawn for all clients,

the only other thing to check is if the Transform failed they could be at location (0,0,0)

1 Like

If I call the event from other clients, the actor is spawned correctly too, but with the same exception as the server, it is spawned only on the client that called it and the other clients on the network can see this spawned actor, but on the other clients the actor is not spawned

Look Client 3 calls event

wait, it is spawning on all clients. ie every client can see the green box

what you mean is you want it to spawn for all players?

if so, on the server call, GetAllActorsOfClass(Player)->CallEvent(SpawnCube)

2 Likes

I want exactly this effect (spawn for all clients) after the initial call. Example: Client 1 call to spawn, the actor will be spawned in all clients in network

CLient 1 calls to Spawn…

The same actor need to be spawned in
Client 1
Client 2
Client 3
Server

this is correct though, the green box is spawned on all clients. ie every client can see the same green box above player 3.

if you want multiple green boxes thats different

1 Like

Thanks for everyone’s help, you guys are the best!

This is the key word “GetAllActorsOfClass(Player)->CallEvent(SpawnCube)” to solve my problem, thank you very much, the solution is exactly this, see the result, now all actors are spawned in all client, this is exactly what I need, thank you very much.

See the result:
Animated gif

x 00_00_00-00_00_30

1 Like

If you want “all connected clients” to spawn a cube, then the best approach is go through controller to Game Mode and have the GM loop the Game State Player Array.

For Each (Player Array) : Get Pawn → Spawn Actor of Class (set owner && Instigator)

This will have the GM spawn a replicated cube for each connected client.

Note: The GM only exists on the Server. Clients do not get a copy of the class, So you have to RPC to server and have the Servers proxy call the GM.


1 Like

Awesome, thank you very much, I learned something more by looking at your code.

It’s amazing how this clears up many doubts I had about how to access all the players in the room and run events on the network. :100:
We can access and change any data through GM

It worked perfectly. I see that you used the “Get Pawn” reference in the loop, I didn’t do it that way, I threw the direct connection in the loop (going through all the items of the class), maybe that’s why I had some errors in the past using loop, your code seems to be better, because it filters the reference only for “Pawn”, this is a way to customize loop, filtering only what is interesting in the reference, very good :clap:

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