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. Dismiss Notice

Question Dynamic Entities not rendered in Editor Viewport

Discussion in 'Graphics for ECS' started by davidus2010, Mar 23, 2023.

  1. davidus2010

    davidus2010

    Joined:
    Dec 4, 2017
    Posts:
    72
    Hello, I'm trying to render entities that have meshes which are being created at runtime. This is now working fine in the "game" viewport/camera, however the editor scene view camera does not render these Entities. Is this just not supported and converted/baked entities still just use the GO renderer, or is there something I might be missing?
    This is what it looks like in the editor (see the plane for a position reference, I am looking at the correct position).

    upload_2023-3-23_22-21-23.png

    Using Entity Graphics 1.0.0-pre.44 with unity 2022.2.6f1
     
  2. davidus2010

    davidus2010

    Joined:
    Dec 4, 2017
    Posts:
    72
    So in case anyone else runs into this issue: It seems like the EntitiesGraphicsSystem just does not draw to the inspector, but only in the game viewport. If I understand this correctly the editor viewport is always drawing just the gameobjects, whether in edit or at runtime. To solve this issue I created a small system that does the job (with suboptimal performance, but it does work):
    Code (CSharp):
    1. [UpdateInGroup(typeof(PresentationSystemGroup))]
    2. [WorldSystemFilter(WorldSystemFilterFlags.Default | WorldSystemFilterFlags.Editor)]
    3. public partial class EditorDrawingSystem : SystemBase {
    4.   protected override void OnUpdate() {
    5.     var hybridRenderer = World.GetOrCreateSystemManaged<EntitiesGraphicsSystem>();
    6.  
    7.     var sceneView = SceneView.lastActiveSceneView;
    8.  
    9.     Entities.WithoutBurst().WithAll<YourComponentHere>().WithNone<DisableRendering>().ForEach((in LocalToWorld localToWorld, in MaterialMeshInfo renderDesc) => {
    10.       var mesh = hybridRenderer.GetMesh(renderDesc.MeshID);
    11.       var material = hybridRenderer.GetMaterial(renderDesc.MaterialID);
    12.  
    13.       Graphics.DrawMesh(mesh, localToWorld.Position, localToWorld.Rotation, material, 0, sceneView.camera);
    14.     }).Run();
    15.   }
    16. }