So yeah, I wanna spawn a prefab here's what I got (Note: my prefab is just a cube with a mesh renderer and mesh filter):
using Unity.Entities;
using UnityEngine;
public class SpawnerAuthoring : MonoBehaviour {
public GameObject prefab;
}
public class SpawnerBaker : Baker<SpawnerAuthoring> {
public override void Bake(SpawnerAuthoring authoring) {
Entity entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entity, new SpawnerComponent {
prefabEntity = GetEntity(authoring.prefab, TransformUsageFlags.Dynamic)
});
}
}
public struct SpawnerComponent : IComponentData {
public Entity prefabEntity;
}
and then I attempt to spawn it in:
using Unity.Entities;
using Unity.Transforms;
using Unity.Burst;
using Unity.Mathematics;
using UnityEngine;
[BurstCompile]
public partial struct _TestSpawner : ISystem{
private EntityManager entityManager;
public void OnCreate(ref SystemState state){
entityManager = state.EntityManager;
public void OnUpdate(ref SystemState state){
foreach (RefRO<SpawnerComponent> spawner in SystemAPI.Query<RefRO<SpawnerComponent>>()){
Entity prefab = spawner.ValueRO.prefabEntity;
Entity instance = entityManager.Instantiate(prefab);
entityManager.SetComponentData(instance, LocalTransform.FromPosition(new float3(i * 5, 0, 0)));
}
}
state.Enabled = false;
}
public void OnDestory(ref SystemState state){
}
}
it does successfully spawn into the entity hierarchy, but nothing actually renders (no cube, no mesh, just empty space) what's going on here?
