Hello, I’m not sure why, but my entity doesn’t appear at all in my scene (game and scene window), and I don’t have any errors.
I think either the MeshInstanceRenderer not work or the SetSharedComponentData not update correctly.
using Unity.Entities;
using Unity.Mathematics;
using Unity.Rendering;
using Unity.Transforms;
using UnityEngine;
public class Bootstrap : MonoBehaviour
{
public Mesh PlayerMesh;
public Material PlayerMaterial;
private void Start()
{
var entityManager = World.Active.GetOrCreateManager<EntityManager>();
var playerArchetype = entityManager.CreateArchetype(
typeof(TransformMatrix),
typeof(Position),
typeof(MeshInstanceRenderer)
);
var player = entityManager.CreateEntity(playerArchetype);
entityManager.SetComponentData(player, new Position { Value = new float3(0f, 0f, 1f) });
entityManager.SetSharedComponentData(player, new MeshInstanceRenderer
{
mesh = PlayerMesh,
material = PlayerMaterial
});
}
}
I stumbled into this trouble too. I do have the Hybrid Renderer package installed (Unity 2019.2.3.f1)
I have attached the manifest.json file in case someone wants to check .
I have this situation in the Entity Debugger which might give a clue.
I tested in Unity 2019.1.1 and 2019.2.3.f1 and the problem is the same. The Entities are created but I can see nothing.
Am I doing something wrong?
Or is the DOTS stack conflicting with Post Processing?
Or, maybe more likely, I noticed that in every Entity, WorldRenderBounds extents is (0,0,0), could that be the cause?
Any help would be super!
Answering myself. I noticed that LocalToWorld was all 0 in every entity which led me to realize I forgot to add a Translation component when creating the archetype.
Translation is pretty much needed for anything that has to be rendered, am I right?
See ADDED LINE (line 22)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Unity.Collections;
using Unity.Rendering;
using Unity.Transforms;
using UnityEngine.Assertions;
public class WAMParticleSystemWIthECS : MonoBehaviour
{
[SerializeField] Mesh mesh;
[SerializeField] Material material;
void Awake() {
// Grab the entity manager instance
EntityManager entityManager = World.Active.EntityManager;
// Create an entity archetype
EntityArchetype entityArchetype = entityManager.CreateArchetype(
typeof(BoidComponent),
typeof(Translation), // ADDED LINE
typeof(RenderMesh),
typeof(LocalToWorld)
//typeof(WorldRenderBounds)
);
// Allocate NativeArray to collect the entities
NativeArray<Entity> entities = new NativeArray<Entity>(4, Allocator.Temp);
// Create an entity from the archetype
entityManager.CreateEntity(entityArchetype, entities);
for (int i = 0; i < entities.Length; i++) {
Entity entity = entities[I];
// Use the entity manager to set the component's data
entityManager.SetComponentData<BoidComponent>(entity, new BoidComponent {
position = new Unity.Mathematics.float3(0.1f, 0.1f, 0.1f),
velocity = new Unity.Mathematics.float3(0.01f, 0.01f, 0.01f),
rotation = Unity.Mathematics.quaternion.Euler(new Unity.Mathematics.float3(0f,10f,1f))
});
Assert.IsNotNull(mesh);
entityManager.SetSharedComponentData(entity, new RenderMesh {
mesh = mesh,
material = material
});
//WorldRenderBounds wrb = entityManager.GetComponentData<WorldRenderBounds>(entity);
//wrb.Value.Extents = new Unity.Mathematics.float3(100f, 100f, 100f);
//entityManager.SetComponentData(entity, wrb);
}
// free
entities.Dispose();
}
}
The reason is that in previous Entity package, RenderBounds is automatically added to your entity, but this is not the case for the newest Entity package.
Not working is there any change in Oct 2020 I cant render the entity.
My code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Unity.Rendering;
using Unity.Transforms;
using Unity.Mathematics;
public class ECS : MonoBehaviour
{
[SerializeField]
private Mesh entityMesh;
[SerializeField]
private Material entityMaterial;
void Start()
{
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
EntityArchetype entityArchetype = entityManager.CreateArchetype(
typeof(RenderMesh),
typeof(LocalToWorld),
typeof(RenderBounds)
);
Entity entity = entityManager.CreateEntity(entityArchetype);
entityManager.SetSharedComponentData(entity, new RenderMesh {
mesh = entityMesh,
material = entityMaterial
});
}
}
I would suggest you try to instantiate your entities from a prefab, since that will always set up the correct components on conversion. If this is not possible you can read the conversion system setting up the required components in Unity.Rendering.Hybrid/MeshRendererConversion.cs in the hybrid renderer packages.
We are currently in the process of moving some components around to reduce both GPU and CPU memory usage so the exact components needed might vary from release to release. A utility function for spawning renderable entities are planned but it’s not yet implemented.