Pure ecs -> setting destination

Hi!

I have switched to trying to implement pure ecs so added components based on what is listed in FollowerEntity script.
I am have setcomponentdata for MovementControl to set targetpoint.
Is there something else I need to do to trigger the entity to start moving?
I am guessing i need to createSystem to add the related systems into my ECS world?

thanks

If you having trouble with your authoring component, I have a working one here with no gameobject syncing and has and editor script similar to the default FollowerEntity.

I have been changing the DestinationPoint to move, not the MovementControl. I found that any systems you make that change the DestinationPoint should have these tags to ensure it doesn’t cause multiple repaths in a single frame.

[UpdateInGroup(typeof(Pathfinding.ECS.AIMovementSystemGroup))]
[UpdateBefore(typeof(Pathfinding.ECS.FollowerControlSystem))]

If you have multiple systems you can just order them within the group so that the highest priority is the last one to update.

1 Like

thanks i’ll take a look…


so this is how I am attempting to create the systems as indicated by FollowerEntity - A* Pathfinding Project
I keep getting the constraints issue with CreateSystem for FollowerControlsystem

I set the destination for entity by setting targetPoint in MovementControl.

Is this the correct steps?

Hmm well im not exactly sure on this one. I have only been digging into ECS for a couple months, but I never had to create the A* systems like this. From what I understand its only needed if the system has DisableAutoCreation, which I don’t think the Pathfinding ones do. If you run the game the systems should be auto added to the Entities Hierarchy at the bottom.

The MovementControl.targetPoint doesn’t seem to work when I change it. I suspect DestinationPoint overwrites it in some system.

Not sure how much stuff you have done with Entities or which version of Unity your on, but in 2022.3 you can change to Runtime view while the game is running and play with the Enitity Component Datas to see what works. Its an obscure little circle icon in top right of inspector.

You have a typo there. It should be MovementPlaneFromGraphSystem.

The destination should be set on the DestinationPoint component.

ah apologies for typo and i am now setting the destination correctly

still trying to add those systems in but i am getting the following errors. might be a jetbrains ide issue.

so after setting the destination in destinationpoint, its still not moving. is there something else i need to set or check?

inspecting the entity i can see DestinationPoint component being updated correctly

for context this is what i am doing to setup the entity

I think a handful of those AddComponents need data passed in. The default data that is set by just adding them probably isn’t enough. In the FollowerEntityAuthoring I made, there is a comment on the ones that don’t seem to need any initial data.

I am also wondering how you are getting the entity and adding these components. If your creating an entity and adding components from a Monobehaviour, it won’t start moving the Gameobject that the Monobehaviour is on. There is no connection between Gameobject and it’s entity counterpart unless you set that up, which is what the Sync components are for but I don’t know how they work. If that is what you want then you would be better off using the FollowerEntity hybrid approach.

If your going for pure ecs you should have a Gameobject in a subscene with authoring Monobehaviours that use the Baker class to add components.

ah ok… i was hoping that at least, after attaching the components and setting destination, the localtransform component is updated constantly with the entity moving towards the final destination and then i can write a system to synch between gameobject transform and localtransform component

for my case, i currently have a GO that runs the bootstrap script we have to set everything up and start a state machine. Then we create entity and add the various components to said entities

i am not familiar with baking yet

Sounds like the same problems I went through when I started playing with Entities. I suspect your entity is moving around when you set the destination, you just can’t see it since it doesn’t have renderers and isn’t updating the Gameobject transform that has renderers. To confirm, set the DestinationPoint and see if the LocalTransform values are changing.

Baking is pretty easy once you get the hang of it. Many of the Unity components like colliders and mesh renderers have automatic authoring so you can just add them without any additional Baker script. Entity rendering needs URP or HDRP though. The big difference is the use of subscenes, anything in a subscene is converted to an Entity and if it has Bakers those are also applied to the entity.

no localtransform isn’t updated. destinationpoint.destination has changed but localtransform.position hasnt changed

if i use Inspector and directly manipulate the localtransform position, i can see my GO moves to the new position so i know my synching system is working

If syncing is working then it must be what I mentioned about default values for all those AddComponents then.

For example the first one, MovementState, takes a Vector3 position parameter which would be your transform.position. The one I had the most trouble with is ManagedState because of it’s need for a persistent allocator, which is why my solution has an ISystem to handle it post entity conversion.

i set some of the default values but still no dice :frowning:

reason we are attempting to do pure ecs is we also intend to use Unity Graphics so essentially besides managers/bootstrap, nothing else is a GO in the world (even the entities that are moving around and using pathfinding)

Ya that is what I am doing also, all entites and no gameobjects, the performance is well worth it. Your definitely going to need to use Authoring Monobehaviours with Bakers eventually. I would try to get my FollowerEntityAuthoring working and figure out how you can integrate it with your bootstrap script after.

ah i realized i didnt need to add those systems in since unity ecs will add them automatically

is it possible that the entity is not picked up in any of the queries in AIMoveSystem thus its not moving?

ok i tried to copy followerentity stuff into my entity setup script but no dice.
i tried using what you have @Curtis in FollowerEntityAuthoring and after creating my own transform sync system, its working!

the behavior is kinda odd though (compared to just using FollowerEntity script. like it will make 1 big detour to reach what is seemingly a straight forward path) and when I turn on local avoidance its even odder… like it will not be able to move more than a few pixels before seemingly getting stuck or it will move in a totally opposite direction.

I get some weird behaviour like that in the editor sometimes but I thought it was something else. It might be an issue with my authoring script :thinking:

Try it in a build, if it works perfectly then it’s same issue I am getting and is a bug in my authoring script.

Are you using my customized Editor script also? Im wondering if that is the cause since for me it’s editor only issue.

actually i am still using my own script. i just copied and pasted your addcomponentdata bits over into my function in my script…

so no baking etc… wondering if that’;s the issue…

Do you use the ISystem that’s in my script to initialize the ManagedState.PathTracer? I found that to be required for a Baked Entity, but not sure about if it’s needed for your solution.

so i am not using a Isystem class to intiialize the pathtracer
we have a state machine initialized by bootstrap script that then creates the entity and attaches the astar components to entity