So I have this Baker that creates two entites, one for the simulation part, one for the visual part
private class MatchActorAuthoringBaker : Baker<MatchActorView>
{
public override void Bake(MatchActorView view)
{
var visualEntity = GetEntity(TransformUsageFlags.Dynamic);
var logicEntity = CreateAdditionalEntity(TransformUsageFlags.Dynamic);
AddComponent<MatchActor>(logicEntity);
SetComponent(logicEntity, new MatchActor
{
Health = view.Settings.Health,
// sets a few fields...
});
view.LogicEntity = logicEntity;
AddComponentObject(visualEntity, view);
}
}
But when I try to access the Logic entity through the View later, it always throws the exception
protected override void OnUpdate()
{
var grid = SystemAPI.ManagedAPI.GetSingleton<GridTerrainView>();
foreach (var (mov, turnActionEntity) in SystemAPI.Query<RefRO<ProcessedTurnActionMovement>>()
.WithEntityAccess())
{
if (!TryGetActorView(mov.ValueRO.Entity, out var viewEntity))
throw new InvalidOperationException("No matching view entity found for movement action.");
// some more code
}
}
bool TryGetActorView(Entity logicActorEntity, out Entity viewEntity)
{
foreach (var (view, entity) in SystemAPI.Query<MatchActorView>().WithEntityAccess())
{
if (view.LogicEntity == logicActorEntity)
{
viewEntity = entity;
return true;
}
}
viewEntity = Entity.Null;
return false;
}
Why is this comparison not working? Is there anything special to be aware when working with CreateAdditionalEntities?