Spawning actor on client and getting a reference to it

Hi there, i have the current problem.

I am using a “Run on server” custom event to spawn an Actor and i need the client to keep a reference of the spawned actor.

I am failing so far, the Actor is spawned, but no reference is saved in the client (since the spawn is happening in the server and i can’t set outputs for custom events).

Help please, i am new to replication. Ty in advance.

you just have to add an “Actor reference” variable to the blueprint spawning the actor (probably your player controller ?) and replicate it. You just have to set this variable with the actor returned from the spawn function

ty for the help, but still not working.

I am getting a reference, but i m not sure its right, it seems its a reference to the Server version of the actor, not the client one.

Will try more later.

This var will have different name depending of client/server version. In fact, the duplicated version will be “translated” depending of the client. I’m using this system and it works perfectly !

Are you using a “Switch has authority” on the spawning event?.

What i tried is:

Custom event “Run on server” >>Spawn Actor >> Set actor reference.

When i do this and Play the game with “Run dedicated server” option, the actor will spawn and i will have a reference, but all variables seems to be wrong, maybe null. My UI should be displaying things like my current life, but this is failling even when those variables are replicated too.

But if instead of this i just do a Hit and get all actors close to me, then set the reference , the variables DO show in the UI this time.

I have this event on the player character blueprint.

Note: I also added a print string + actor display name. if i dont’ use switch has authority it seems like it is spawning 2 actors ( one might be the server version, i don’t really know) but the client only sees one. With the switch has authority only spawns one. In any case, the client seems to not be able to read the reference variables and display them in the UI.

edit|delete| more ▼
Newest
answered 6 secs ago
D2liriuM gravatar image
D2liriuM
1 ● 1 ● 1

Switch has autority is usefull only on event that can be called in client and server version. if you use a Run On Server, you don’t need it.

Then, variable may take some times to be replicated (on my local project it’s 2~3 frames)

In fact, I don’t know if it’s the best option, but I initialize my pawn client side only when the variable is replicated and arrived on the client.

if they don’t have the same name, it’s not a problem, when PIE I have PB_Name_1 on the server variable, and BP_Name_2 on the client and it works fine !

Thanks man, i will try again now and see what happens.

Edit: Tried again, now its working. The variables didn’t show up because of a fail cast on the UMG. But the reference is good.

The only problem i have now, is that with the

Custom event “Run on server” >>>Spawn>>>set reference i am spawning 2 pawns instead of one, it seems, that the server spawns one and then the client spawns another one. (I have dedicated server option when play).

I solved this by adding a “Do once” node in the custom event and is now spawning only 1 pawn.

I have doubts about this do once, i don’t know if it is the proper way to do it. I don’t know why is happening or if i am doing something wrong.

Any ideas?.