Search Unity

IL2CPP build not showing MeshInstanceRenderer components (attached to Entities)

Discussion in 'Graphics for ECS' started by Trindenberg, Nov 18, 2018.

  1. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    398
    Hi all,

    I've been messing around with ECS for a little while now. Interested on how it might run with IL2CPP. However, when I build using IL2CPP the entities are created (as they are counted) but there are no visible meshes. The meshes are not being created as the frame rate stays the same however many I create.

    Have looked for answers but can't find them anywhere.

    What is interesting, is that the GameObject which has a MeshInstanceRenderer component for reference, shows the mesh for this one object when IL2CPP build. So it doesn't have an issue with the component type. But if I build using Mono, my entities show, but this GameObject reference doesn't which I believe is correct.

    I have tried creating the MIR manually as I create the entity rather than by reference, but still no show.

    Do MIRs not work with IL2CPP without a GameObject (rather than an Entity)?
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Can you provide little bit more info? Code where you create pure entity with MIR and Position and/or Rotation and/or Scale
     
  3. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    398
    Code (CSharp):
    1. using UnityEngine;
    2. using Unity.Entities;
    3. using Unity.Rendering;
    4. using Unity.Transforms;
    5. using Unity.Mathematics;
    6.  
    7. public class BootStrap
    8. {
    9.     private static EntityManager            entityManager;
    10.     private static MeshInstanceRenderer     meshInstanceRenderer;
    11.     private static EntityArchetype          entityArchetype;
    12.  
    13.     //public ComponentGroup componentGroup;
    14.  
    15.     public static int numberOfEntities;
    16.  
    17.     private static int randomEntityVariableIndex;
    18.  
    19.     public static Settings settings;
    20.  
    21.     public struct RandomEntityVariables      
    22.     {
    23.         public float3       scale;
    24.         public float3       position;
    25.         public Quaternion   rotation;
    26.         public Vector3      rotationMod;
    27.         public float3       direction;
    28.         public float        moveSpeed;
    29.         public int          destroy;
    30.         public float        life;
    31.     }
    32.  
    33.     private static RandomEntityVariables[] randomEntityVariablesArray;
    34.  
    35.  
    36.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    37.     private static void Initialise()
    38.     {
    39.         entityManager   = World.Active.GetOrCreateManager<EntityManager>();
    40.         entityArchetype = entityManager.CreateArchetype
    41.             (  
    42.                 typeof(InitialScale),
    43.                 typeof(Scale),
    44.                 typeof(Position),
    45.                 typeof(Rotation),
    46.                 typeof(Direction),
    47.                 typeof(MoveSpeed),
    48.                 typeof(Life)
    49.              );
    50.  
    51.         //World.Active.GetOrCreateManager<MoveOnDirectionSystem>().Enabled = false;
    52.  
    53.         randomEntityVariablesArray = new RandomEntityVariables[100000];
    54.  
    55.         float randomMeshScale;
    56.  
    57.         for (int i = 0; i < 100000; i++)
    58.         {
    59.  
    60.             randomMeshScale = UnityEngine.Random.value;
    61.  
    62.             randomEntityVariablesArray[i].scale        = new   float3(randomMeshScale, randomMeshScale, randomMeshScale);
    63.             randomEntityVariablesArray[i].position     = new   float3(0f, 0f, 0f);
    64.             randomEntityVariablesArray[i].direction    =       UnityEngine.Random.onUnitSphere;
    65.             randomEntityVariablesArray[i].rotation     =       Quaternion.LookRotation(randomEntityVariablesArray[i].direction);
    66.             randomEntityVariablesArray[i].rotationMod  =       UnityEngine.Random.insideUnitSphere / 2f;
    67.             randomEntityVariablesArray[i].moveSpeed    =       UnityEngine.Random.Range(0.1f, 20f);
    68.         }
    69.     }
    70.  
    71.  
    72.     [RuntimeInitializeOnLoadMethod (RuntimeInitializeLoadType.AfterSceneLoad)]
    73.     private static void InitialiseWithScene()
    74.     {
    75.         settings                = GameObject.FindObjectOfType<Settings>();
    76.         meshInstanceRenderer    = GameObject.FindObjectOfType<MeshInstanceRendererComponent>().Value;
    77.  
    78.     }
    79.  
    80.  
    81.     private static void SpawnMeshEntity (MeshInstanceRenderer meshInstanceRenderer, int i)
    82.     {
    83.         Entity meshEntity = entityManager.CreateEntity(entityArchetype);
    84.  
    85.         entityManager.SetComponentData          (meshEntity, new InitialScale { Value = randomEntityVariablesArray[i].scale });
    86.         entityManager.SetComponentData          (meshEntity, new Scale        { Value = randomEntityVariablesArray[i].scale });
    87.         entityManager.SetComponentData          (meshEntity, new Position     { Value = randomEntityVariablesArray[i].position });
    88.         entityManager.SetComponentData          (meshEntity, new Rotation     { Value = randomEntityVariablesArray[i].rotation });
    89.         entityManager.SetComponentData          (meshEntity, new Direction    { Value = randomEntityVariablesArray[i].direction });
    90.         entityManager.SetComponentData          (meshEntity, new MoveSpeed    { Value = randomEntityVariablesArray[i].moveSpeed });
    91.         entityManager.SetComponentData          (meshEntity, new Life         { Value = UnityEngine.Random.Range (0f, 2.5f) });
    92.  
    93.         entityManager.AddSharedComponentData    (meshEntity, meshInstanceRenderer);
    94.     }
    95.  
    96.     public static void SpawnMultiple ()
    97.     {
    98.         for (int i = 0; i < settings.burstSize; i++)
    99.             {
    100.                 meshInstanceRenderer.material       = settings.materials[i % 4];
    101.  
    102.                 SpawnMeshEntity (meshInstanceRenderer, randomEntityVariableIndex);
    103.  
    104.                 randomEntityVariableIndex++;
    105.             }
    106.  
    107.         if (randomEntityVariableIndex == 100000)    randomEntityVariableIndex = 0;
    108.     }
    109. }
    110.  
     
  4. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    398
    I'm also using the HDRenderPipeline. I believe I tried with standard and that doesn't make a difference. Also tried disabling Instance Variant stripping. Also disabled Static Batching.
     
  5. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    May be helpful:
    in your case (if use second suggestion) Unity.Rendering.Hybrid instead Unity.Entities.Hybrid
     
  6. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    398
    Ok, tried that still no show! I've tried most things. What I need to do is try Graphics.DrawMeshInstanced to see if instancing is working at all with IL2CPP outside of an Entity. I was only really interested in the speed comparison (addicted to optimisation!)