Search Unity

Instantiating entity prefab containing data of other entity prefab?

Discussion in 'Data Oriented Technology Stack' started by Buretto, Apr 21, 2019.

  1. Buretto

    Buretto

    Joined:
    Mar 23, 2015
    Posts:
    34
    I am getting this error:
    ArgumentException: A component with type:Translation has not been added to the entity.

    but the entity I am trying to instantiate is an entity that was created from a
    GameObject
    prefab using the
    ConvertToEntity
    script; so it should have
    Translation
    by default right?

    I think I am getting this error because of the way I am getting the entity data.

    Here is my setup:
    1. I created a
      GameObject
      prefab (I'll call it meteoroid), which contains the
      ConvertToEntity
      script, and a proxy mono behavior for the
      ISharedComponentData
      Destructible
      .
    2. The Destructible proxy contains reference to two
      GameObject
      prefabs, one called
      HitEffect
      , and the other called
      DestroyEffect
      ; both have the
      ConvertToEntity
      script. These are converted to entities using the
      GameObjectConversionSystem
      in the
      Convert
      method and stored in the
      ISharedComponentData
      .
    3. A "Spawner" proxy mono behavior contains a reference to the meteoroid prefab and converts it to an entity and stores in the Spawner
      IComponentData
      .
    4. A Spawner
      ComponentSystem
      instantiates copies of the meteoroid entity everywhere randomly.
    5. If a bullet raycast hits a meteoroid, it adds a
      IComponentData
      HitData
      , which stores the entity it hit and hit position etc..
    6. Finally, a Hit
      ComponentSystem
      looks for any entity with
      HitData
      , grabs the entity from it and gets its
      Destructible
      property. It looks through it, and instantiates either the
      HitEffect
      or
      DestroyEffect
      ; this is where I am getting the error.
    AddComponent
    does not work for me in this situation as all the other data from the prefab is also gone (including the rendering components). So I want to ask, is it possible to convert and instantiate prefabs that are stored in other converted prefabs? Or what am I doing wrong?
    Here is code: gist
     
    Last edited: Apr 22, 2019
  2. Buretto

    Buretto

    Joined:
    Mar 23, 2015
    Posts:
    34
    Okay I just found that it works only if the referenced prefab is a child of the prefab trying to reference it. I suspect it is because as soon as the "parent" prefab is converted to an entity, it somehow loses reference to where the other prefab is located. Is there a way around this, so I can have a prefab reference another prefab that are not other-wised linked?