#Spawning Object With Context

1 messages · Page 1 of 1 (latest)

agile cypress
#

I've looked around for this in the past but I'm approaching the problem again and looking for some general advice, Is there a good way (either directly or via some pattern) to spawn an object with Netcode For GameObjects with any amount of contextual data?

In my single player stuff I tend to have this kind of spawning setup

ScriptableObject contains Prefab
ScriptableObject has function that spawns Prefab, gives the Prefab the ScriptableObject used to spawn it, then returns the spawned Prefab

But with spawning via NGO (and if I wanted to spawn objects async) you obviously can't directly get the spawned instance back as a return value which makes that abit trickier. I was hoping there was a good way for me to do something kinda like

1. Server gets given a ScriptableObject & Prefab to instansiate
2. Server stores the "request" along with the scriptableobject as context in some sort of collection
3. Server spawns Prefab
4. On Prefab NetworkSpawn, Prefab finds that "request" collection and obtains the context used to spawn the object

With that in mind, Is there a reliable value I can use as a key to associate this requested spawn with the instance that is going to exist?

Let me know if something doesn't make sense and/or additional context is needed 😄

languid pendant
#

OnSynchronize might be what you want

If you have multiple clients sending spawn requests and you need to match them with a local instance, I would send something like a Guid along with the request. That Guid can be added to the spawned object by the server