Nav Links - simple way to detect if an AI is using one

A common problem people seem to have when using complex Nav Link (or Smart Nav Link) systems to control special jumps, climbing, vaulting, using ladders, etc, is a seeming inability to determine via blueprints if an AI is actually using a link at any point. The ‘On Smart Link Reached’ event does not seem to work very well at all, if at all, and only tells you about unidirectional Smart links, not bidirectional or simple ones. Luckily, I have a very simple work-around which can tell you, on demand, if an AI is using a Nav Link.

That’s it. Very simple. The output is true if the AI is currently using a Nav link, false if not. Now this does not tell you which link, of course, or which direction it is being used in, and some logic is needed to scan the AI’s proximity, find the nearest Nav Link and so on, but I hope this alone is helpful to some of you.

Using this method, I’ve managed to get my AIs to reliably make heroic leaps across gaps, mantle up obstacles, climb ladders, crawl under things, dive into water, and so on.

2 Likes

I would ask, why is this information useful?

A NavLink, on its own, only allows an AI to clumsily drop off ledges which it otherwise wouldn’t be able to do. If you can detect WHEN an AI is using one, however, you can invoke whatever other actions you might want. If for example, I want an AI to climb a ladder, a NavLink can tell the navigation system that you want to join one part of the nav-mesh (the bottom of the ladder) to another (the top), but it doesn’t do anything to make the AI actually use a ladder. Without any other code, the AI will simply fall off from the top or fumble around at the bottom until it decides to re-navigate. Detecting that the AI is actually using the link, however, allows you to code a specific action.

2 Likes

I’m legitimately trying to understand why this is useful, as I’ve implemented a large amount of custom navlink handling, without ever having to know this. When you hit the Smart Link Reached event, you start the action. I can’t see a specific use for “is a specific pawn in a link” . . .

Well, I can think of a few reasons:

  1. This works with simple links and smart links, whereas the Smart Link Reached event only works with smart ones (and doesn’t seem to work all that well IMHO - it appears to misfire or fire off the wrong links in UE5).

  2. The Smart Link Reached event tells you nothing about when an agent has finished using a link, only that it’s been reached (and thus started). If, for example, you wanted a ghost AI to walk through a wall, you’d probably want to turn off its collisions when it started using the NavLink, then on again when it had finished. Because my above method returns a boolean value, you could use that to switch collision on/off. Smart Link Reached isn’t a boolean - it’s a fire and forget. If it was supported by a corresponding ‘On Smart Link Finished’ event, then I agree, my method would be somewhat pointless. But it doesn’t have one.

  3. You can use this boolean value to set slots on a NavLink so that only one agent can use it at a time. A ladder, for example, can look crappy if two or more agents are trying to scramble up it, even worse if one agent is going up as another is going down. When an agent begins using a vacant ladder, you can set the AreaFilter to null to prevent any other agents from using the link, then back to normal when the agent using the link has finished (a bit like slots in Smart Objects).

1 Like

hmm. Although it’s not exposed to blueprint (at least in 4.27 which is the source i’m using and able to search easily right at the moment), there is a corresponding OnLinkMoveFinished event in NavLinkCustomComponent. I haven’t personally had a strong desire to implement that as a Blueprintable event, but that’s actually a pretty good idea for your point 3, as I presently trigger a timer to start as long as the move will take to re-enable a smart link that i don’t want multiple AIs travelling through simultaneously. However, for that specific one, there’s a significant time delay needed after the move is complete, as well. So that might not help me either.

Also, just remembered as I’m editing this, you can also connect to the incoming AI’s OnMoveCompleted event (just make sure you disconnect afterwards!) and use that in the SmartLink to know when the move has either finished or aborted while in progress.

I do wonder if setting area to null would have any advantages or disadvantages over my current setting a link disabled when i don’t want anyone to use it. Theoretically, there’s some system for notifying other pawns in the nearby area when a link goes disabled, but as far as I can tell, it looks like the code for it was taken out by someone in Epic’s history and never fixed. (i should maybe look at that in the Ue5 branch)

I could be wrong, but IMO, simple links are only useful if the AI in question has no setup required – it can already navigate between two disconnected pieces of mesh, without anything else telling it how. I think a smart link is required if you have to do anything special, like setup the character or ai to specifically handle it. Am I wrong there?

Oh, also NavLinkProxy has access to HasMovingAgents(), which is blueprint accessible too, might be useful. It does say “smart link” on it’s comment, though.

I do feel like NavLinkCustomComponent wasn’t 100% completed and could use some extra features…

Hello my friend,
I tried your method and sadly it doesnt work for me :slightly_frowning_face:
It shows me that the nav link index is -1 all the time and current nav index shows 0.
It doesnt change :confused:

You’re probably calling the Move functions regularly and recalculating the path on the regular.

In any case, after reviewing this thread, I still can’t figure out what you would use the OP for.

You’re an angel, thank you!

I am developing a plugin based on this concept. Initially, the goal was to implement AI agents in the Game Animation Sample project, where, as you know, the characters are capable of climbing obstacles.

Here is the video documentation: https://www.youtube.com/watch?v=WrACxoSwlbY&list=PL-AU5Owdz4HiTHMELT4B-3o6Ge_SrBMtx&index=8&ab_channel=CRYOMEN