Search Unity

  1. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice

Help Wanted Entity Prefab/Mesh change?

Discussion in 'Data Oriented Technology Stack' started by Slarti-42, Jan 5, 2021.

  1. Slarti-42

    Slarti-42

    Joined:
    Jul 1, 2019
    Posts:
    48
    Hi folks,

    all the best for this new year.
    I have been toying around with this, but I was not successful.
    What I want to do is that when something happens to an entity, it changes its form.

    I have 50 cube entities and when one of the cubes is reaching something, or hitting something, it changes to a sphere.
    (PostUpdateCommands?)

    Does anyone have an idea?

    Thanks in advance.
    Slarti
     
  2. Slarti-42

    Slarti-42

    Joined:
    Jul 1, 2019
    Posts:
    48
    Somebody has an idea please?
     
  3. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    784
    hi Slarti,
    I think you have several options to do what you want, the first two ideas that come to my mind are:
    1) switch from a MeshRenderer scd to another every time an entity triggers your event.
    or
    2) instantiate a new entity with a different MeshRenderer scd and fill it with the old entity components.
     
  4. StickyMitchel

    StickyMitchel

    Joined:
    Sep 2, 2019
    Posts:
    12
    One possibility could also be to have a Parent Entity that holds all data and connect the visual of the Cube/Sphere to that parent entity. Then when the parent entity reaches the trigger make it delete the current visual and spawn in the new visual as a child.
     
    Slarti-42 likes this.
  5. scottjdaley

    scottjdaley

    Joined:
    Aug 1, 2013
    Posts:
    13
    In my project I've gone the route of swapping the RenderMesh SCD. I store the RenderMeshes of all my converted prefabs in a system.

    This works well enough, but because RenderMesh is a SCD, it can't be stored in a NativeHashMap or other native container. For now, I've just put these in a normal Dictionary, but I've heard that the unsafe containers may also work here. Curious if anyone has a different solution to this.

    I've also considered the approach of storing the mesh as a child entity, but I didn't want to pay the cost of the transform system for no reason. I also find that a flatterer hierarchy is easier to reason about in ECS. But I think this can still make a lot of sense if you have a bunch of components that map 1 to 1 with your mesh and you want to swap all of them at once.
     
    Slarti-42 likes this.
  6. Slarti-42

    Slarti-42

    Joined:
    Jul 1, 2019
    Posts:
    48
    Thanks all for the answers. I will try this.
    @StickyMitchel could you share some code, how to address and replace the parent/child, please?
    Thanks
     
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    8,635
    This sounds resenable.
    I woul also try similar alternative way, where parent having two children entities, mesh0 and mesh1.
    Then depending on parent state, setting Disabled component, on corresponding child.
    Optionally DissableRendering component, but then transform is still calculated.

    Setting children is done automatically, when setting parent. But few conditions are to be met, while components are required. I. E. LocalToWorld. Local To Parent, rotation, position and I think few others.
     
unityunity