The entities is not visible

Hi!

Preface:
Unity version: 2019.1.f1
Entities package version: 31

So… I followed this tutorial:

It is an outdated tutorial so I made some changes to it. In particular I changed InstanceMeshRenderer to RenderMeshProxy. So there are no errors. 3 entities created. However there are no visible entities.

If you see at single entity you would see the following picture:

So as you may see there is no mesh here… To say the truth I don’t understand why.

Here is a code that creates the entities:

using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using UnityEngine;
using Unity.Transforms;
using Unity.Rendering;
using Unity.Mathematics;

public class RTSBootstrap
{
    public static EntityArchetype PlayerUnitArchetype;
    private static RenderMesh cubeRenderer;
    private static EntityManager entityManager;

    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    public static void Initialize()
    {
        entityManager = World.Active.EntityManager;

        PlayerUnitArchetype = entityManager.CreateArchetype(
            typeof(Translation),
            typeof(Rotation),
            //typeof(MoveSpeed),
            typeof(PlayerInputComponent));
    }

    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
    public static void InitalizeWithScene()
    {
        cubeRenderer = GetLookFromProto("CubeProto");

        StartRTSGame();
    }

    public static void StartRTSGame()
    {
        for (int i = 0; i < 3; ++i)
        {
            Entity playerUnit = entityManager.CreateEntity(PlayerUnitArchetype);
            entityManager.SetComponentData(playerUnit, new Translation { Value = new float3(i * 5, 0.5f, 0.0f)});
            entityManager.AddSharedComponentData(playerUnit, cubeRenderer);
        }
    }

    public static RenderMesh GetLookFromProto(string protoName)
    {
        var proto = GameObject.Find(protoName);
        var result = proto.GetComponent<RenderMeshProxy>().Value;
        return result;
    }
}

StartRTSGame is the function that actually creates entities.

Hope someone could help

Thanks in advance.

4515541–417808–Test1.rar (68.3 KB)

This is all very specific stuff, but a quick guess is to add this to your ArcheType:

typeof(LocalToWorld),
typeof(NonUniformScale),
typeof(RenderMesh),
typeof(WorldRenderBounds),

LocalToWorld enought

2 Likes

Thank you. However this is not helped. Would you be so kind to take a look at the project ? I’ll upload it at the very first post.

I don’t see a sample project, only a code snippet. But anyhow, you need LocalToWorld, Translation, and RenderMesh for the mesh to show up.

If I add only this component the everything is OK. Could you please tell why ?

LocalToWorld is the matrix that defines the transform (translation, rotation, and scale). It is needed by the Hybrid Renderer to work on RenderMesh. Translation and Rotation are convenience components that make it easier to work with LocalToWorld (changing Translation and Rotation will also update LocalToWorld accordingly).

1 Like

Thank you so much for your help!
I now have some time to learn about ECS. So I am still newbie in that area.
The components is just data, right ? If so, then having Translation component is redundant since the LocalToWorld component have to be on the entity. I do not see logic here.

Yeah it’s actually been brought up a few times here before. I actually don’t know why Translation is needed here. Last time I checked, you’d need Translation in addition to the LocalToWorld in order for the mesh to show up.

Generally speaking, Translation and Rotation are meant to make things easier to work with, and their sizes are smaller than LocalToWorld, so they take up less space in the chunk (if you want to work on them selectively).

But you’ll get all the info you need here: TransformSystem | Package Manager UI website

(The most detailed doc page we have right now)

1 Like

Thanks a lot! It is very useful link.(Though I still do not undestand the purpose of that decision). Probably the main purpose is to make it easier to use the Component for transforming the object, but that comes with more memory taken by a single entity

using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Rendering;
using Unity.Transforms;
using UnityEngine;

[UpdateInGroup(typeof(SimulationSystemGroup))]
public class CubeGameSystem : JobComponentSystem
{
    protected override void OnCreate()
    {
        base.OnCreate();
        //var myCube = EntityManager.CreateEntity(
        //    ComponentType.ReadOnly<LocalToWorld>(),
        //    ComponentType.ReadOnly<Translation>(),
        
        //     ComponentType.ReadOnly<Rotation>(),
        //        ComponentType.ReadOnly<NonUniformScale>(),
        //    ComponentType.ReadOnly<RenderMesh>(),
        //    ComponentType.ReadOnly<RenderBounds>()
        //);
        //EntityManager.SetComponentData(myCube, new Translation
        //{
        //    Value = new float3(1, 2, 3)
        //});
        //EntityManager.SetComponentData(myCube, new Rotation
        //{
        //    Value = quaternion.identity
        //});
        //EntityManager.SetComponentData(myCube, new NonUniformScale
        //{
        //    Value = new float3(1, 2, 3)
        //}) ;
        //EntityManager.SetComponentData(myCube, new LocalToWorld
        //{
        //    Value = new float4x4(rotation: quaternion.identity, translation: new float3(1, 2, 3))
        //});
        //EntityManager.SetComponentData(myCube, new RenderBounds
        //{
        //    Value = new Bounds(Vector3.zero, Vector3.one * 100).ToAABB()
        //}) ;

        var ah = Resources.Load<GameObject>("assethold").GetComponent<AssetHolder>();
        //EntityManager.SetSharedComponentData(myCube, new RenderMesh
        //{
        //    mesh = ah.mesh,
        //    material = ah.myMT
        //});

        EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

        // 1
        EntityArchetype archetype = entityManager.CreateArchetype(
            typeof(Translation),
            typeof(Rotation),
            typeof(RenderMesh),
            typeof(RenderBounds),
            typeof(LocalToWorld));

        // 2
        Entity entity = entityManager.CreateEntity(archetype);

        // 3
        entityManager.SetComponentData(entity, new Translation { Value = new float3(-3f, 0.5f, 5f) });

        entityManager.SetComponentData(entity, new Rotation { Value = quaternion.EulerXYZ(new float3(0f, 45f, 0f)) });

        entityManager.SetSharedComponentData(entity, new RenderMesh
        {
            mesh = ah.mesh,
            material = ah.myMT
        });
    }

    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        return default;
    }
}

can not see still!!!what is wrong?

1 Like

Set proper RenderBounds. Yours - zero.

6240539--687182--bug2.png

  EntityManager.SetSharedComponentData(myCube, new RenderMesh
        {
            mesh = ah.mesh,
            material = ah.myMT
        });
        EntityManager.SetComponentData(myCube, new RenderBounds
        {
            Value = new Bounds(Vector3.zero, Vector3.one * 1).ToAABB()
        });

STILL NOT WORK


It seems HDRP Setting make no mesh showing,if NO HDRP ,it work…what 's wrong?

I check again ,and sure it is HDRP make this rendermesh broken.