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

Applying an Attach component to Camera causes errors

Discussion in 'Entity Component System' started by ryancole, Nov 17, 2018.

  1. ryancole

    ryancole

    Joined:
    Oct 8, 2017
    Posts:
    18
    Hi folks,

    I'm trying to make the camera in my scene follow a moving cube around. In my basic understanding, I can use the Attach component to set up a parent-child relationship between the Camera and my cube. I understand this is to basically be a two step process ...

    1. Apply an Attach component to the Camera in my scene
    2. Write a System that moves that Camera around, relative to my cube

    I'm unsure yet how I will achieve number 2, but I'm still stuck on number 1. Whenever I apply the Attach component to a Camera in my scene, I begin to get the following error ...

    Code (CSharp):
    1. ArgumentException: All entities passed to EntityManager must exist. One of the entities has already been destroyed or was never created.
    2. Unity.Entities.EntityDataManager.AssertEntitiesExist (Unity.Entities.Entity* entities, System.Int32 count) (at Library/PackageCache/com.unity.entities@0.0.12-preview.19/Unity.Entities/EntityDataManager.cs:326)
    3. Unity.Entities.EntityManager.AddComponent (Unity.Entities.Entity entity, Unity.Entities.ComponentType type) (at Library/PackageCache/com.unity.entities@0.0.12-preview.19/Unity.Entities/EntityManager.cs:385)
    4. Unity.Entities.EntityCommandBuffer.PlaybackChain (Unity.Entities.EntityManager mgr, Unity.Entities.ECBSharedPlaybackState& playbackState, Unity.Collections.NativeArray`1[T] chainStates, System.Int32 currentChain, System.Int32 nextChain) (at Library/PackageCache/com.unity.entities@0.0.12-preview.19/Unity.Entities/EntityCommandBuffer.cs:970)
    5. Unity.Entities.EntityCommandBuffer.Playback (Unity.Entities.EntityManager mgr) (at Library/PackageCache/com.unity.entities@0.0.12-preview.19/Unity.Entities/EntityCommandBuffer.cs:871)
    6. Unity.Transforms.TransformSystem.UpdateDAG () (at Library/PackageCache/com.unity.entities@0.0.12-preview.19/Unity.Transforms/TransformSystem.cs:353)
    7. Unity.Transforms.TransformSystem.OnUpdate (Unity.Jobs.JobHandle inputDeps) (at Library/PackageCache/com.unity.entities@0.0.12-preview.19/Unity.Transforms/TransformSystem.cs:1145)
    8. Unity.Entities.JobComponentSystem.InternalUpdate () (at Library/PackageCache/com.unity.entities@0.0.12-preview.19/Unity.Entities/ComponentSystem.cs:507)
    9. Unity.Entities.ScriptBehaviourManager.Update () (at Library/PackageCache/com.unity.entities@0.0.12-preview.19/Unity.Entities/ScriptBehaviourManager.cs:77)
    10. Unity.Entities.ScriptBehaviourUpdateOrder+DummyDelagateWrapper.TriggerUpdate () (at Library/PackageCache/com.unity.entities@0.0.12-preview.19/Unity.Entities/ScriptBehaviourUpdateOrder.cs:703)
    11.  
    Does anybody know why this is happening? My assumption is that the Attach component needs a Parent and Child, but when applied via the editor I don't yet have the opportunity to assign those. I'm unsure how else to do this, though.

    Any ideas? Thanks!
     
  2. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    Any entities with an Attach component will be destroyed by the EndFrameTransformSystem after being processed, so you don't want to have an Attach component on the Camera. Instead you should create a brand new entity with just an Attach component. The Entity type is not serializable by the Unity Editor, so you'll have to assign the Parent and Child of the Attach component via code. My workaround was to create a ComponentSystem which allows you to automatically build an entity hierarchy (via creating entities with an Attach component) based on the data shown in the Hierarchy Window.
     
    ryancole likes this.
  3. ryancole

    ryancole

    Joined:
    Oct 8, 2017
    Posts:
    18
    Thank you for that info. That clears it up a lot.

    Where did you learn that it worked this way? Just trial and error, or here on the forums, or somewhere else? It still seems to me like the best way to stay up-to-date with ECS "documentation" is by reading forums and just keeping a mental note about things.
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    Vacummus likes this.