Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Best approach to spawn different entities based on binary data

Discussion in 'Entity Component System' started by MantridJones, Nov 17, 2020.

  1. MantridJones

    MantridJones

    Joined:
    Oct 9, 2014
    Posts:
    20
    Hi there,

    I was wondering about a good approach to spawn various different Entities, at different times, based on some binary data I read from a file, that will be interpreted inside a job.

    I think a System is a good idea, since it allows me to determine when it will execute in relation to other Systems that will do work on the spawned Entities. However, the spawner itself should not run (OnUpdate) right from the start. It should only start after I handed it the NativeArray<byte> filled with the spawn data that I read from a file. It also doesn't require any entities. It should just run it's OnUpdate every frame after I told it to start, until I tell it to stop. But I'm not sure what the best approach is to do this. Using a SingletonEntity "SpawningInProgress" that I don't really need, just to get the OnUpdate() method to execute? And how would I go about passing the NativeArray<byte> to the System? Using a static class or just having it passed into a member from a function?

    I've been using Burst and IJobs for a while but as far as Systems are concerned, I'm very uncertain about the best practices (unless of course the standard use case of always run for queried entities).
     
  2. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    Singleton Entity is a good way to go, make it have a singleton IBufferElement for your bytes, so instead of reading/writing to a NativeArray<byte> you will use a DynamicBuffer for that.
     
    MantridJones likes this.