Improbable Icon

Worker startup sequence

unity
worker

#1

Hello.

I have a voxel terrain represented by a grid of entities. When a worker starts it receives these entities and generates terrain meshes (separate set of GameObjects with its own grid and managed by my code) which takes about a minute even with the simplest algorithms.

There are also NPCs (and potentially players) that are moving on the terrain.

Problem is, if an NPC is loaded before the terrain is generated, it falls through. I have a temporary workaround with worker startup freeze time. Do you have any existing pattern to deal with such problems? I am using Unity3d for client and server workers.

I imagine dynamic chunk assignment will not work for my prototype too. Is there a document describing chunk assignment, entity loading and unloading?


#3

Hey @fitialovks! We’re currently working on a Recipe for best practices around spawning terrain in your world. In the meantime, have a look at @callumb’s tips here–maybe some of them will be useful for your issue!

I’d also recommend reading the Intro to Workers to get your head around how chunks are assigned and load balanced! Hope that helps!


#4

Hi @fitialovks!

In SpatialOS 11.0 the entity creation pipeline for Unity was overhauled. It now allows you to heavily customize how the worker (an instance of Unity in your case) handles instructions from SpatialOS regarding entities that gain or lose relevance to that worker.

One option for you would be to customize this pipeline so that createEntity instructions for NPCs are suppressed until after the UnityWorker knows that the terrain has been loaded (perhaps triggered by some signal given by the terrain GameObject’s OnAwake function, or something similar). You’ll then be able to defer the NPC’s spawning until after the terrain is ready.

Take a look at the entity pipeline doc, and let me know if you have any questions!