Nav: Add NavStop component
See original GitHub issueHi @reeseschultz ,
I tweeted you just the other day regarding issues I’m having stopping an agent. Thought I’d start a discussion on here as it will be easier! So, in my project, I’m creating a couple of different component data structs to handle agent actions. For example:
public struct NavGoTo : IComponentData
{
public float3 Location;
}
public struct NavStop : IComponentData
{
// nothing here
}
public struct NavWander : IComponentData
{
// nothing here
}
Then in my movement system I have
// Handle NavWander
Entities
.WithAll<NavWander>()
.WithNone<NavHasProblem, NavNeedsDestination, NavStop>()
.WithReadOnly(renderBoundsFromEntity)
.WithNativeDisableParallelForRestriction(randomArray)
.ForEach((Entity entity, int entityInQueryIndex, int nativeThreadIndex, in Parent surface) =>
{
if (
surface.Value.Equals(Entity.Null)
) return;
var random = randomArray[nativeThreadIndex];
commandBuffer.AddComponent(entityInQueryIndex, entity, new NavNeedsDestination
{
Destination = NavTools.GetRandomPointInBounds(
ref random,
renderBoundsFromEntity[surface.Value].Value
)
});
randomArray[nativeThreadIndex] = random;
})
.WithName("NavWanderSystem")
.ScheduleParallel();
...
// Handle NavStop
Entities
.WithNone<NavHasProblem, NavWander>()
.WithReadOnly(translationFromEntity)
.WithNativeDisableParallelForRestriction(translationFromEntity)
.ForEach((Entity entity, int entityInQueryIndex, in NavStop navStop) =>
{
commandBuffer.RemoveComponent<NavStop>(entityInQueryIndex, entity);
commandBuffer.AddComponent(entityInQueryIndex, entity, new NavNeedsDestination
{
Destination = translationFromEntity[entity].Value
});
Debug.Log($"Stop entity ${entity.Index}");
}).WithoutBurst()
.WithName("NavStopSystem")
.ScheduleParallel();
Barrier.AddJobHandleForProducer(Dependency);
Ok, so this works - sometimes! Everytime I add a NavStop
the system correctly picks this up and I see the DebugLog. However, the agent doesn’t always stop. I’ve tried quite a few different things (been at this simple stop functionality for about 4 days! lol) and while I’m new to ECS, I can’t for the life of me figure out why what I’m doing shouldn’t work… the fact it sometimes works makes it even more frustrating. I’m wondering if it could be something to do with the way NavNeedsDestination
works and so my next step was to ask you for some advice. Can you think of any reason why setting the Destination to the entities Translation won’t work?
Just to note, I’ve also used the Translation in the ForEach lambda rather using var translationFromEntity = GetComponentDataFromEntity<Translation>(true);
but get the same result.
Any thoughts? Would really appreciate any insight you might have.
Thanks
Edit: Maybe it’s because I’m using .ScheduleParallel()
and they are conflicting? It appears as though .Schedule
improves things slightly but there is still and issue.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@P-Stringer I added
NavStop
, which is part of Nav v0.15.0. You can view the changes in this commit. It should work. I tested it in theNavHybridDemo
by making the agent stop whenTab
is pressed (sometimes the agent’s animation freezes—that’s a separate, scene-specific issue). Anyway, I really appreciate that you brought this up, and also that you tried to apply a workaround and shared the code for what you did (most people don’t). I was able to knock this out this morning since I don’t have much time later today.Be aware that the
feat/demo-overhaul
has not been synced withmaster
, meaning it’s missing later changes that that were added tomaster
. Like I said, I’ll try to sync them, but it’ll be at least a week before I can do that. There’s noNavFollow
component in that branch (yet!), but the underlying code should now be ready to support it, is what I mean. I know it should be about ready because the new “Stranded” demo supports click-and-drag movement.Glad it helps!