Set when AI should start roaming

Hello,

i am trying to set up my AI to start roaming after a precise event.
I want the AI to spawn (it will be good also to use set visibility) and start roaming across my patrol path after i pick a key. I was thinking to use a branch with a bool condition “HasCharKey?” and make “set hascharkey” inside the blueprint Key, but i think i am in the wrong direction. Any idea? Maybe i should edit the behavior tree? Because my initial toughts were more focused on the step before “execute behavior tree” in the AI Enemy blueprint.

I add some print screen of what i got in mind (which obviously doesnt work):

And this is the error shown after i click play:

Thanks in advance!

Hi ElegantLooter!

This would be a perfect opportunity to use an Event Dispatcher!

Here’s the Official Documentation for it:
https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/Blueprints/BP_HowTo/EventDispatcher/
So what you’ll do is
1: Add an Event Dispatcher (Below Variables in the My Blueprint section) to your Start_Enemy BP and name it “Second Floor Alarm” or something.
image

2: Put in a Call to that Dispatcher after you Set Has Reached 2nd Floor on your overlap event.
3: Open your AI Controller blueprint. Make a variable of object type and search for SPECIFICALLY your trigger box object type, name it StartTrigger or something. Anywhere near BeginPlay, drag in that reference.
4: Drag off of the StartTrigger and make a node called “BindEventTo2ndFloorAlert”.
5: Drag off the red square, make a custom event, and run behavior tree!


This will only call that event when the dispatcher call goes out from the start trigger.
I really hope this gets you moving! Let me know how it goes!

Hello and thanks for your help!
I tryed to follow your tip, but i think i did something wrong:



In my AI enemy controller i got other nodes, it could be the cause?

Thanks again for your help! I really appreciate it!

Hey again ElegantLooter!

You’re actually doing great! Let’s add in a few things and check something.
Firstly, let’s add an IsValid check to that first screenshot! It’ll go after BeginPlay but before BindEvent, and plug in StartTrigger to that IsValid. Off the False end of the IsValid do a PrintString to see if anything is set in StartTrigger. Have the message in print string say whatever you want, we just want to find out if the StartTrigger is being set!

Let me know if that prints when you start the game, and I’ll have more for you when you get back based on if it does or doesn’t! :smiley: Either way it will get rid of your error message, but it might not fix your functionality yet.

Hello and thanks again!

I configured the blueprint as it following:

And i get the printed text as soon as i click play. After 2 seconds it goes away and whenever i pass through my box collision, nothing happens and nothing gets printed

And i still get this error after i close the game:


:smiling_face_with_tear:

I cant wait to know what are you about to tell me :smiley: Thanks again!!!

Okay! Let’s get to it!

You’ll want to keep that IsValid check just in case.
Now you need to set a default for your StartTrigger. Here’s what we’re gonna do! With this setup you’ll be able to set each AI to have whatever StartTrigger box you’d like, so you could do this with the 3rd floor, 4th floor, etc!

Step 1: Open your Character that will be using this AI Controller. Go to your MyBlueprint area with the variables list, make a new variable that’s basically identical to StartTrigger from your AI_Controller and you’ll want to click this guy right here!
image
Make that eyeball open! That will let us set things per individual enemy in your level!

Step2: Go back to your viewport, find your character in your level, select him and go to your details panel. Search for “StartTrigger” and there should be a box for you to input your object. This says “Hey, this is the Trigger object I want this character to use.”

image
You can use the dropper to select your target object easily!

Step 3: Go back to your AI controller and SET THAT THANG! RightClick out in the open and the node you’re looking for is Get Owner (ActionsComp). It’s a special node only accessible by Components. Then go for something like so!

Give that a try and get back to me! That SHOULD fix everything!

Thanks for your tips!! As soon as i get home i will try! Thank you again, you are amazing!

Hello ElegantLooter and Mind-Brain.

I think learning about Dispatchers is a something to be understood.

However, not knowing about whatever ElegantLooter is making, I am concerned, for him, that this implementation may not work as expected if level streaming is utilized for the listeners in the unloaded level may not be in the game yet and as a result would miss that dispatcher call event.

A valid concern???

Hello vespineauto007 and thanks for your reply! Actually my level is quite small and the location where the enemy hunts the player its quite small. I am not using level streaming so i dont think i will have problems. I am currently trying to setup the tips given from Mind-Brain but i need to figure out what am i doing wrong since i cannot link the StartTrigger variable to the SET variable:

image

Thanks to both for your help!

Hey again all!

@vespineauto007 I wouldn’t be worried about it with their level size, but good catch!

@ElegantLooter this picture is in the AI Controller, right? You need to pull off of “Main Enemy Brand new” and GET the CharacterStartTrigger variable (or whatever the one on your character is named) from it. The SET needs to be your AI Start Trigger variable here in the AI controller. There shouldn’t be a “Target” pin. That’s about all that can be gathered with just this screenshot, we need more context to keep going.

Let me know if this helps!

Hello Mind-Brain and thanks again for you reply!

So…here what i did, this time i’ll send you more complete print screens so you can understand what i am currently doing.

This is the BP Start_AI (the box collision):

And this is the Enemy AI Controller:

Here you can see the new variable that i have created on the Enemy:

I placed the BoxCollision BP near the enemy just to make tests:

But it seems that i made some mistakes since the IsValid check still is Not Valid…

Thanks for your help!!

Hello @Mind-Brain, hope you doing well!

Do you by any chance read my update?

Thank you in advance and good evening!

I did just now! Thanks for your patience @ElegantLooter!

So what the IsValid check is checking is to make sure that you have a specific object in the scene selected. Right now you just have it set to be of the TYPE of object you want, but not the specific one. You need to
1: select your enemy in the viewport/game window itself,
2: scroll down the details window and find your “StartTriggerCh” variable.
image

3: click on the dropperimage

4: click on your Box2ndfloor Actor in the world details window. (The one I made to explain this has a static mesh but it’s whatever :P)
image

Give that a try and get back to me! I’ll be here for a while.

Hello @Mind-Brain and thanks again for your reply!

I set everything following your tips, this is my current situation:

But i still get the error :smiling_face_with_tear: I am wondering what could be the problem in this case :face_with_spiral_eyes:

Thanks!

Hey again ElegantLooter!

SO CLOSE! OK, try putting a Delay node with .1 as the time after the Not Valid and loop it back to the IsValid? If that doesn’t work, take it back out.

Failing that: Can you run it and give me a screenshot of the error code? The entire thing?
Also can you click on the final link in the error code, zoom out a bit so I can see, and give me a screenshot of that? Everything seems to be set right.

Hello @Mind-Brain and thanks for your answer!

So far this is the current situation after set the delay:


The only working link in the error is the SetValueAsBool:

Thanks in advance for your patience and support!
Have a nice day!

Hey @ElegantLooter,
OKAY! SO! We’re gonna do a couple of things.

Thing 1 is we’re gonna put in a printstring after Cast To BP_NotesCharacter and before the SetValueAsBool. Plug the Return Value into that, (it’ll convert it to a string).

Run the game and get within sight radius to see if it gives you the name of the Blackboard you’re using. If it doesn’t, there’s the issue.

If it does return your BB’s name correctly, we’re gonna delete that and move on to:

Thing 2. Go to your BlackBoard and make sure that the name of that Bool on your BB is 100% the exact same. A SPACE AT THE END CAN MESS IT UP. No fooling.

Failing that stuff let me know and we’ll regroup!

Hello @Mind-Brain and thanks for your answer!

Unfortunately, i think that the make literal name is correct:

I am running out of hope :frowning:

I add that the displayed name is the BB key, not the name of the Blackboard itself :grin:

No, don’t run out of hope! Solving problems like these… you’ll be over the moon when it works!

Ok now we need to make sure the Character Controller is set to the correct one. So your enemy should be MainEnemy_BrandNew. Go to your class defaults and make sure the Controller is set to be MainEnemyNew_AI. It’ll be here in this spot.

After that, check and make sure the MainEnemyNew_AI has the BT set correctly. Because upon closer inspection, the error is saying it’s not finding the Blackboard return value off of the Get Blackboard node.

On your MainEnemy_NewAI add an “EventOnPossess” node and attach a “RunBehaviorTree” node. Now that I’m looking I don’t see one. Massive overlook on my part. Put that in and get back to me! I want to see this thing MOVE! :smiley: