AI NPCs break with elevator

I have some NPCs wandering around with moveto a random location. It works great, the npcs move around randomly, pathing correctly.

I place some “elevators” (at run time) that are functionally just smart links. I Bind Event to On Smart Link Reached and that event gets the npcs location and destination, sends it to the NPC bp, and runs an elevator move event to manually move them:

They do occasionally hit the smart links and a print text verifies that they do. I am having two problems with this though:

First, the second an elevator is placed, the NPCs go from correct, smooth movement from random place to place to moving erratically, seemingly ignoring the navmesh and going wherever they want (walking into walls, getting stuck on objects, standing still, jittering in place, etc…)

Second, when they do occasionally make it to the elevator, they seem to get “stuck” for a while and dont continue on to where they were pathing when they first hit the smart link. When/if they continue moving again, they go right back along the smart link they took.

Any clues as to what is going on?

I you haven’t already, first I would suggest deleting the simple links in the link proxy actor. I’ve had problems before with npcs jittering under a platform the smart link is trying to tell them to jump up to. Seemed to be the smart link and dumb link fighting or something. Second, instead of smart link calling a timeline to move the actual actor, might be better to set a blackboard key that has them wait in the elevator. and have it physically carry the actor. Would probably need a dispatcher in elevator bp to inform listening passengers they’ve arrived at floor tho (or maybe just oneway smartlinks for exiting elevator?). Might also want an invisible floor inside the elevator shaft at each stop with a custom collision channel which chars are set to ignore while riding. Just to ensure nav recast finds the path. Even if using dynamic navmesh, it can be slow to update moving platforms.

I have tried deleting the simple links, and tried adding them back with the same locations as the smart links. Neither had an effect.

I wasnt sure what a blackboard key is, so I did a quick search. That seems to apply to behavior trees, which I am not using (yet). I think it may be time to set that up in case this is the solution. There is no platform in the elevator (its just a tube they float in, think star trek tractor beams) but I guess I could make an invisible one. I’m not sure if I can make that work or not because of the following:

An additional complication is that the elevator isnt one piece. Its actually made of modules (top, shaft, tee, bottom) and assembled in game, like subnautica structures. Each piece has its own nav link proxy and an invisible floor that the smart links connect to, so they have a navmesh to connect to.

The newer state tree system might be better than behavior tree for this. Either way,having a branch or state for riding may help teh ai not to freak out. As for modularity, you could use trigger volumes under invisible floors to turn off a collision response on begin overlap, like in the sidescroller variant of the 3rd person project template.

Might also be worth testing a direct teleport instead of vinterping to see if it’s the wait causing AI to panic lol. If teleport works may just need a behavior or state tree to pause ai decision making.

I havn’t gotten to check out any tree systems yet, but I fixed some of the issues. I adjusted the manual move to put the NPCs just above the destination point (by half the NPC height) instead of right at it. I also found a setting in the NPC character movement called stop movement abort paths. It was on. Once I turned it off, they mostly continue their path after getting moved in the elevator. Turning off can walk off ledges and turning on requested move acceleration seemed to help with most of the erratic behavior when not pathing through the elevator.

Now I’m left with this: Occasionally the NPCs will go out of bounds of the nav mesh as shown in this video.

I am also still having issues with the NPCs getting “stuck” in the elevators, as well as a new issue where they now sometimes go up the elevator half way, then go right back down then through the floor as shown in this video.

Hopefully someone has seen similar behavior and knows how to fix it. I’d really like to get these issues resolved before I try to add any kind of behavior tree, so I don’t end up compounding the problems.

EDIT: I did a test with a direct moveto to an actor set on the top floor of the square module. The NPCs path correctly to it at first, until they hit the bottom floor of the elevator, then they stop and don’t proceed further. Clearly the stop movement abort paths wasn’t the only thing interrupting the pathing. They do consistently keep their path through the midpoint between the elevators and only stop pathing correctly when they hit the destination point of the bottom smart link.

Is there a way to edit smart link points from a blueprint? Ive managed to get the elevator movement mostly working, but I still have glitches where the elevator parts meet and the npc needs to “hand off” from one smart link to another. If I could move the smart links at run time, I wouldn’t need to do a hand off at all and I think that would fix my remaining problems.

I couldn’t find a node to do it in BP, so I tried to make a C++ helper for it and it didn’t work. Here is what I did:

BPNavLinkCustomComponent.h:

#pragma once

#include "CoreMinimal.h"
#include "NavLinkCustomComponent.h"
#include "BPNavLinkCustomComponent.generated.h"

/**
 * 
 */
UCLASS(meta = (BlueprintSpawnableComponent))
class GAME_API UBPNavLinkCustomComponent : public UNavLinkCustomComponent
{
	GENERATED_BODY()
	UFUNCTION(BlueprintCallable)
	void SetSmartPoints(FVector NewStart, FVector NewEnd);
	
	
	
};

BPNavLinkCustomComponent.cpp:

#include "BPNavLinkCustomComponent.h"


void UBPNavLinkCustomComponent::SetSmartPoints(FVector NewStart, FVector NewEnd)
{
    this->LinkRelativeStart = NewStart;
    this->LinkRelativeEnd = NewEnd;
}

It gave me a blueprint node, but the relative start and relative end in the nav link stayed at the default 70,0,0 and -70,0,0. Did I do something wrong or is this just not doable?

I found a workaround! I was unable to set the points no matter how I tried. Luckily, the points will always be vertical from each other. Because of this, I was able to re-scale the navlinks to make it work.

In the construction script of the elevator components, I check for elevator parts that have exits above and/or below the newly placed part (depending on what part it is). Then I move the child actor navlink, which already has its points spaced appropriately for adjacent elevator parts, to the halfway point between the two modules and scale the navlink to match the distance between the elevator parts that have exits.

Now my NPCs can move along the elevator and do not lose their pathing, get stuck in the elevator, or pause in elevator modules that do not have exits.

I am not sure why the NPCs were getting stuck off path when not using the elevator, but this change seems to have fixed that too.

EDIT: This only partially works, but its a step in the right direction. I did not consider multiple exits in this solution, and it seems you cannot spawn an actor in the construction script. Does anyone know how to get around this?

Once I got everything working smoothly with one exit, I tried moving the construction script code to being play. Everything is working perfectly (for the elevators) and I can spawn multiple links to match the multiple exits.

The NPCs going off path and getting stuck issue came back, but I found that it was unrelated to elevators and instead was somehow related to having more than one of a different module. Still haven’t figured that one out, but I started a different thread for it.