# Spawning actor on client and getting a reference to it

**URL:** <https://forums.unrealengine.com/t/spawning-actor-on-client-and-getting-a-reference-to-it/359838>\
**Category:** Blueprint\
**Tags:** unreal-engine, Blueprint, question\
**Created:** [June 6, 2016, 3:31pm UTC](https://forums.unrealengine.com/t/spawning-actor-on-client-and-getting-a-reference-to-it/359838 "2016-06-06T15:31:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![D2liriuM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@D2liriuM](https://forums.unrealengine.com/u/D2liriuM)\
**Post date:** [June 6, 2016, 3:31pm UTC](https://forums.unrealengine.com/t/spawning-actor-on-client-and-getting-a-reference-to-it/359838/1 "2016-06-06T15:31:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mdonge](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mdonge](https://forums.unrealengine.com/u/mdonge)\
**Post date:** [June 6, 2016, 4:58pm UTC](https://forums.unrealengine.com/t/spawning-actor-on-client-and-getting-a-reference-to-it/359838/2 "2016-06-06T16:58:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![D2liriuM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@D2liriuM](https://forums.unrealengine.com/u/D2liriuM)\
**Post date:** [June 6, 2016, 6:22pm UTC](https://forums.unrealengine.com/t/spawning-actor-on-client-and-getting-a-reference-to-it/359838/3 "2016-06-06T18:22:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mdonge](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mdonge](https://forums.unrealengine.com/u/mdonge)\
**Post date:** [June 6, 2016, 8:01pm UTC](https://forums.unrealengine.com/t/spawning-actor-on-client-and-getting-a-reference-to-it/359838/4 "2016-06-06T20:01:00Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![D2liriuM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@D2liriuM](https://forums.unrealengine.com/u/D2liriuM)\
**Post date:** [June 7, 2016, 8:45pm UTC](https://forums.unrealengine.com/t/spawning-actor-on-client-and-getting-a-reference-to-it/359838/5 "2016-06-07T20:45:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mdonge](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mdonge](https://forums.unrealengine.com/u/mdonge)\
**Post date:** [June 8, 2016, 8:35am UTC](https://forums.unrealengine.com/t/spawning-actor-on-client-and-getting-a-reference-to-it/359838/6 "2016-06-08T08:35:55Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![D2liriuM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@D2liriuM](https://forums.unrealengine.com/u/D2liriuM)\
**Post date:** [June 8, 2016, 11:50am UTC](https://forums.unrealengine.com/t/spawning-actor-on-client-and-getting-a-reference-to-it/359838/7 "2016-06-08T11:50:54Z")

</div>

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?.
