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

How to make entity "disappear"?

Discussion in 'Entity Component System' started by eterlan, May 9, 2019.

  1. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    Edited:
    Actually I found there is a disabled component, which can make entity hidden by query. However, it works only for custom systems, neither renderer or physics care about it. I guess that's bug right?

    Origin post:
    Hi, I want to implement Collection and Inventory System for my game. When I collect some items entity, I add the item an Owner component, and register the item as an element in dynamicBuffer<items> on Owner entity. Everything works fine except the item is still in the world and can be collect again...

    I thought remove anything other than required data (such as restoration value of apple) might be a way to fix the problem, but when player discard the item(to the ground), I need to instantiate different prefab in each circumstance and copy all the data to this new one. Considering there are so many items, I think that's not good.

    In short, I want an entity to be disappeared for a period of time, without run by renderer, transform and physic systems, and then simply come back to the world. Any suggestion would be appreciated.
    .

    BTW, I would glad to know is there any better way to implement Inventory System?:D
     
    Last edited: May 10, 2019
  2. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    In my case, I simply remove all the transform-related comps (LocalToWorld, Translation, etc...) on pickup, then re-add them on discard/drop-to-ground.
     
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    I would rather use DynamicBuffer, or native array, to store inventory, rather than entity per item.
     
    siggigg likes this.
  4. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    Thanks for your suggestion, that sounds good. However, it doesn't work. I mean, after I delete the translation & LocalTW etc, the item are still rendering. I'm using prefab to instantiate item, is that the cause?
     
  5. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    Yeah, that's right, this idea sounds attractive and easy to do.. But I was stuck by how to store different type of struct in dynamicBuffer, such as food and weapon. Any ideas about that?
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    You can use for example int which representing item ID.
    Or have 2 ints in NativeArray/ Buffer, one for item ID, other for amount/count.
     
    eterlan likes this.
  7. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    Thanks a lot! That's a doable approach !