Spawning a new object and passing it to the client

I am spawning a replicated actor, then calling an event on a client with the new actor as a parameter.

image

The “pick up” Event calls another event that is replicated to owning client.

My problem is that the newly spawned object is still invalid when the event call is executed on the client… I can attempt to retry the event after some arbitrary amount of time, but the passed object will always be invalid.

If I instead put a small delay in here everything works as expected.:
image

Is this behavior expected or is this a bug? Is there a better way to accomplish what I am doing?

How do you spawn your actor? ServerEvent => MultiCastEvent => SpawnActor? Or simple SpawnActor with “Replicates” enabled?

The flow would be ServerEvent => SpawnReplicatedActor => OwningClientEvent(SpawnedActor as parameter) => do some cosmetic stuff.

That does not work even if I retry the client logic after a delay… but this does:

ServerEvent => SpawnReplicatedActor => delay(.2) => OwningClientEvent(SpawnedActor as parameter) => do some cosmetic stuff.

If you do it like this you have to wait until the client knows about this Actor, so until it is replicated and valid for the Client. This can take a few ticks.

The odd part to me is that if the object is not valid when the client receives the event call, it will never become valid. I was hoping the client alone could handle waiting for the object to become valid, rather than the server waiting and hoping the object is replicated to the client after x amount of time.

What you could do:

Use ServerEvent => MultiCastEvent to spawn your Actor. So everybody has his own one instantly

User the Server to tell the Client about the spawned Actor => Set the Reference

Check the valid status of the spawned Actor until it is valid and only then execute the ClientEvent

Can you share a project or an example? Or describe what you spawn and where? E.g. do you spawn it in your character? How does the pickup event look like etc

If you spawn the actor in the multicast then you will get a de-sync between the actor. It needs to be created on the server to sync.

Multicast for most scenarios involving spawning should be used for non-critical effects that don’t need to be in sync.

If you spawn an actor on the server how can you then make it visible to the clients?

The actor has to have replication enabled.

1 Like