Search Unity

Feature Request Spawners! Better authoring support for runtime spawned prefabs

Discussion in 'NetCode for ECS' started by Krooq, Jun 2, 2022.

  1. Krooq

    Krooq

    Joined:
    Jan 30, 2013
    Posts:
    196
    Hi NetCode peeps,

    A very very common pattern in NetCode is the spawner pattern.
    You have an entity in your scene that simply spawns a prefab at runtime, often based on some system logic.
    Could be characters, bullets, buildings whatever.

    This works well, but when authoring these things there is often visual to assist with placement and it's just very tedious. Right now I use a little hack where I render the mesh using OnDrawGizmos but this doesn't work for everything. On the road to 1.0, I would love to a good implementation of a spawner authoring script, either from Unity or the community.

    It should have features like:
    - Preview: render the spawn prefab in the scene maybe with a special shader to highlight that its a spawner
    - Spawn Method: once on load, via system logic
    - Target World: client/server/both (useful for "visual only" objects on the client and prefabs with companions)
    - Nesting Support: should be possible to have a spawner as a child of another prefab that triggers when that prefab spawns

    What do you think? Let me know your thoughts and suggestions!
    To me the beauty of Unity is the power of scriptable tooling, I hope we can make netcode so much better by leveraging that.
     
    apkdev likes this.
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    One option is simply making your spawn system to run in the editor world so it actually spawns the prefab for preview.
     
    Krooq likes this.
  3. Krooq

    Krooq

    Joined:
    Jan 30, 2013
    Posts:
    196
    This is a really interesting idea.
    I gave it a go and it sort-of works but there are a several caveats.
    It depends which live-conversion mode you select:
    - If you have authoring mode selected it depends open/closed state of the subscene
    - If you have runtime mode selected it doesn't re-run after reserialization which is quite annoying
    It also doesn't work in prefab editing mode which is really the main thing I want this for.

    Note this was using my actual runtime system just in the editor world so with a bit of tweaking I could probably overcome some of these issues.