Search Unity

Find entity from monobehavior

Discussion in 'Entity Component System' started by andywatts, Apr 21, 2018.

  1. andywatts

    andywatts

    Joined:
    Sep 19, 2015
    Posts:
    112
    How can I find a specific entity from a monobehavior?

    In my monobehavior I tried
    Code (CSharp):
    1. struct Data { public Chunk Chunk; }
    2. ComponentSystem.GetEntities<Data>()
    ... but get the below error...

    Cannot access protected member `Unity.Entities.ComponentSystemBase.GetEntities<Data>()' via a qualifier of type `Unity.Entities.ComponentSystem'. The qualifier must be of type `MyMono' or derived from it

    MyMono is derived from MonoBehaviour and not IComponentSystem, so seems I can't call GetEntities.

    Thanks
     
  2. SubPixelPerfect

    SubPixelPerfect

    Joined:
    Oct 14, 2015
    Posts:
    224
    In general, MonoBehavior is a wrong place to do anything with an entities, better try to avoid it, if it is not possible plese explain your case
     
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    What is Chunk in your code?
     
  4. andywatts

    andywatts

    Joined:
    Sep 19, 2015
    Posts:
    112
    Chunk is a MonoBehavior attached to the game object.
    GameObjectEntity means my mono is visible in the Entity Debugger.
     
  5. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    I don't really understand your problem...

    Is that entity something special? Then use a tag... (pure)
    If it's just a GameObject (hybrit) than use GetComponent<GameObjectEntity>().Entity to get the entity of the specific gameobject

    You can't search for chunk...

    Maybe you can give us some more context.