why might this be happening? I'm trying to instantiate an entity, the gameobject prefab is an empty transform with a renderer as a child. Here are my scripts:
[BurstCompile, UpdateInGroup(typeof(InitializationSystemGroup))] public partial struct SpawnEnemySystem : ISystem
{
[BurstCompile] public void OnUpdate(ref SystemState state)
{
state.Enabled = false;
Entity gameEntity = SystemAPI.GetSingletonEntity<GameProperties>();
GameAspect game = SystemAPI.GetAspect<GameAspect>(gameEntity);
//switch to better command buffer
var ecb = new EntityCommandBuffer(Allocator.Temp);
for (var i = 0; i < game.NumberOfEnemiesToSpawn; i++)
{
var newEnemy = ecb.Instantiate(game.EnemyPrefab);
ecb.SetComponent(newEnemy,
new LocalTransform { Position = game.GetRandomOffset(0.5f, 1)});
}
ecb.Playback(state.EntityManager);
}
}
public struct GameProperties : IComponentData
{
public Entity Enemy;
public int Amount;
}
public struct GameRandom : IComponentData
{
public Random Value;
}
public class GamePropertiesAuthoring : MonoBehaviour
{
public GameObject Enemy;
public int Amount;
public uint RandomSeed;
}
public class GamePropertiesBaker : Baker<GamePropertiesAuthoring>
{
public override void Bake(GamePropertiesAuthoring authoring)
{
Entity entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entity, new GameProperties
{
Enemy = GetEntity(authoring.Enemy, TransformUsageFlags.Dynamic),
Amount = authoring.Amount,
});
AddComponent(entity, new GameRandom
{
Value = Unity.Mathematics.Random.CreateFromIndex(authoring.RandomSeed),
});
}
}
public readonly partial struct GameAspect : IAspect
{
private readonly RefRO<GameProperties> _properties;
private readonly RefRW<GameRandom> _random;
private readonly RefRW<LocalTransform> _transform;
public int NumberOfEnemiesToSpawn => _properties.ValueRO.Amount;
public Entity EnemyPrefab => _properties.ValueRO.Enemy;
public float3 GetRandomOffset(float magnitude, float height)
{
float2 randomPosition2D = _random.ValueRW.
Value.NextFloat2(magnitude * -1, magnitude);
return new float3(randomPosition2D.x, height, randomPosition2D.y);
}
}```