Search Unity

GameObjects Sharing a Mesh. Is it possible?

Discussion in 'General Graphics' started by Mr_Admirals, Jan 9, 2019.

  1. Mr_Admirals

    Mr_Admirals

    Joined:
    May 13, 2017
    Posts:
    86
    Is it possible for multiple GameObjects to share the same mesh? As in, if you had a plane and 4 GameObjects, then each GameObject would control a quadrant of the mesh. If you were to move one of the GameObjects though, the mesh would not separate as if it were a separate object, but would instead stretch along the seam as the vertices are shared.

    Hopefully that makes sense. Let me know if I can elaborate.
     
  2. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,277
    This could be done, it would involve having 4 gameobjects that each have individual meshes - then there would need to be code that would "connect" the "edge" vertices to the same spot, making it as if it's a single mesh.

    Of course, optimizations would need to be done - such as only regenerating meshes when one of the objects moves. :)
     
    Last edited: Jan 9, 2019
  3. Mr_Admirals

    Mr_Admirals

    Joined:
    May 13, 2017
    Posts:
    86
    Thanks for the response!

    Any idea how I would go about connecting the meshes? Or could you break it down further? I'm familiar with the mesh construction process as I'm already subdividing a mesh to work towards this goal, but since the vertices are pass by value, I'm not sure how to go about doing this - unless you mean I'd have to recalculate the supermesh every frame to keep each gameobject mesh consistent?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    You'd be better off having one game object with a script component that procedurally updates a single mesh, and then have that script component have a list of transforms that are used to control the position of the vertices. The other transforms would be on game objects that are essentially dummy game objects with no components (apart from the default transform).
     
    xVergilx, Mr_Admirals and joshcamas like this.
  5. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,277
    ^ I like this approach much more than mine