public class PlayerAuthoring : MonoBehaviour
{
Entity m_Entity;
void Awake()
{
var world = World.DefaultGameObjectInjectionWorld;
var manager = world.EntityManager;
m_Entity = manager.CreateEntity();
manager.SetName(m_Entity, name);
manager.AddComponentData(m_Entity, new Player
{
});
manager.AddComponentData(m_Entity, new LocalTransform
{
Position = transform.position,
Rotation = transform.rotation,
Scale = 1,
});
manager.AddComponentObject(m_Entity, transform);
}
void OnDestroy()
{
var world = World.DefaultGameObjectInjectionWorld;
if (world != null)
{
world.EntityManager.RemoveComponent<Player>(m_Entity);
}
}
}
I am pretty new to ECS and I just want to use ECS as AI pathfinding and keep other logic in Mono. I have a gameObect "Player" that is spawned after the game start, and I want to create a entity from it for just referencing the player position. I dont spawn it in a subscene and I dont have a subscene so I think baker doesnt work? How can I synchronize the player transform to its entity localTransform? Thank you.