Search Unity

Adding multiple mesh renderers to one entity

Discussion in 'Scripting' started by GenPhi, Jul 21, 2018.

  1. GenPhi

    GenPhi

    Joined:
    Dec 27, 2014
    Posts:
    12
    How would you create an entity for an FBX that contains multiple meshes/materials? For example, I have a model with body, hair, eyes, etc... with a separate mesh and material for each.

    I tried using something like this but doesn't appear to work. (Just a recreation of the meshinstancerenderercomponent)
    Code (CSharp):
    1. using System;
    2. using Unity.Entities;
    3. using Unity.Rendering;
    4. using UnityEngine;
    5.  
    6.     [Serializable]
    7.     public struct PlayerUnitAppearence : ISharedComponentData {
    8.         public Mesh BodyMesh;
    9.         public Material BodyMaterial;
    10.         public Mesh HairMesh;
    11.         public Material HairMaterial;
    12.         public Mesh BrowMesh;
    13.         public Material BrowMaterial;
    14.         public Mesh EyesMesh;
    15.         public Material EyesMaterial;
    16.         public Mesh TeethMesh;
    17.         public Material TeethMaterial;
    18.  
    19.         public LightShadowCasterMode castShadows;
    20.         public bool receiveShadows;
    21.     }
    22.  
    23.     public class PlayerUnitMeshRendererComponents : SharedComponentDataWrapper<PlayerUnitAppearence> { }
    Thanks in advance for the help!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Unity should import each mesh as a separate GameObject with its own MeshRenderer.

    If you want to combine meshes into one mesh for some reason, you can google for "mesh combiner" scripts.
     
    GenPhi likes this.
  3. GenPhi

    GenPhi

    Joined:
    Dec 27, 2014
    Posts:
    12
    I thought I might have to do that. I was hoping to be able to add them as a single component. It is probably for the better though as not all of the models have the same meshes. One may have a belt mesh and another may not. Thank you for the response!
     
    Kurt-Dekker likes this.