Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Keeping References to Entities in 0.51

Discussion in 'Entity Component System' started by MNNoxMortem, Jul 15, 2022.

  1. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    Is it safe to keep a reference to an Entity in Managed Code in 0.51?

    I am running into the scenario where it looks like my references are changing under the hood:
    • Some change to different entities
    • Some look like they are reused
    • Some seem to become Entity.Null
    I would like to make sure while fixing this, that keeping the reference in general is safe.

    Does the answer change if I am accessing entities on threads other than the main thread?

    I assumed Entities are safe to be referenced based on this documentation section:

     
  2. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    908
    Depends on how you are getting and saving that reference. There are a lot of pitfalls, especially in conversion stage or with command buffers. Entity references are handled pretty well in ECS world because of patching but stored in MBs that patching isn't there.

    Usually it's safe to keep references.
     
    MNNoxMortem likes this.
  3. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723