Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Is a mesh in ECS shared by default?

Discussion in 'Entity Component System' started by meanmonkey, Nov 9, 2018.

  1. meanmonkey

    meanmonkey

    Joined:
    Nov 13, 2014
    Posts:
    148
    I have a mesh template, which I use for entity creation:

    Code (CSharp):
    1.  MeshInstanceRenderer meshInstanceRenderer = new MeshInstanceRenderer
    2.             {
    3.                 material = _material
    4.                 mesh = _meshTemplate
    5.             };
    6.  
    7.             meshInstanceRenderer.mesh.vertices = _vertices;
    8.             meshInstanceRenderer.mesh.colors = _colors;
    9.  
    As you can see I am modifiying the vertices and colors at each entity creation. Problem is, all entity meshes using the same mesh template are overwritten to the state of the last entity creation.

    So I assume the mesh is force - shared in ecs somehow? Which makes me wonder, as ecs is only using structs and no reference types? My solution worked fine in the "classic" way without ecs.

    Thank you :)
     
  2. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    I hate that about the MeshFilter/MeshSkinnedRenderer interface. Properties that silently instantiate assets but don't take ownership.

    You have to clone (and destroy) the template yourself:
    Code (CSharp):
    1. mesh = Object.Instantiate(_meshTemplate)
     
    meanmonkey likes this.
  3. meanmonkey

    meanmonkey

    Joined:
    Nov 13, 2014
    Posts:
    148
    Thanks man, that worked!