#I need help linking entity to gameobject and gameobject to entity in Unity 6 and the latest Entities

1 messages · Page 1 of 1 (latest)

chrome bridge
#

So I'm following a tutorial on setting up A.I Navigation via query method to leverage on DOTS. Problem now is that the Entity is moving, but the GameObject is not moving. I understand that there are 2 ways to resolve this.
1st Way is to resolve the Entity/Mesh issue where it's not showing up visually.
2nd Way is to attached scripts to both Entity and GameObject so that the GameObject would be able to access the Entity AND the Entity will be able to access the GameObject.

Issue is I'm not sure the best way to do this or are there already components that does this for you? (For the 2nd option)

#

This is the tutorial I'm following: https://youtu.be/boT42zuWjwc?si=aC-WjganlgZnCWx0 However as this tutorial was done a year ago, it may have cause the above issue I'm facing where visually nothing is seen.

NavMeshQuery allows you to use navigation meshes with DOTS, even though NavMeshAgents are not supported. I will show you how to use NavMeshQuery to calculate the path for the enemies, and also how to make them move towards the player. In the next part, we will also make the pathfinding multithreaded for maximum performance.

CODE - https://gith...

▶ Play video
errant merlin
#

Your "2nd way" is an incorrect thinking when working with ECS. For starters, there is no such thing as "attaching scripts to Entity" in ECS.

#

Then "attaching scripts to GameObject so that it can access Entity" is also an inappropriate way to work with Entity.

#

The rule of thumb: you shouldn't acces entities outside from places that are not systems nor jobs.

#

While working with ECS you have to let ECS controls GameObjects, not the other way around.

#

Back to your issue, you can establish a simple link to GameObject (or better, to GameObject.transform) just by using UnityObjectRef.

#
public struct GameObjectTransformRef : IComponentData
{
    public UnityObjectRef<Transform> value;
}
#

In the system that spawn a gameobject for each of your entities, you can assign the GameObject.transform directly to this value field.

#

Then you have another system to synchronize the entity position to this transform ref.