On See Pawn continuing despite bool to stop

So I followed a tutorial that ‘taught’ how to use pawn sensing and it’s been working well until now. When I added in health and death, the health widget and the ability to deal damage to the enemy seems to break entirely. Basically as soon as I add anything other than ‘destroy pawn’ (such as an animation, a delay, etc), I can no longer deal damage to the enemy. I’ve used some debug printing and determined it is not getting stuck at any of the points of the code, it seems to go through all of the code but it ignores/doesn’t execute the things under ‘death’, and I can’t figure out why it’s breaking my attacking.

Basically I have an ‘is dead?’ bool that is set to true upon the enemy taking damage that lowers its health to or below 0 (I know I should use a clamp to keep it just 0 I haven’t gotten to that yet), so that when ‘on see pawn’ executes it checks for if ‘is dead?’ is true and should not execute any of the rest of it if it is. However, despite checking to make sure ‘is dead?’ is for sure being set to true (it is!) it seems to continue through the pawn sensing line as if it were false, or something else is happening that I’m unaware of. To top that off, if the ‘Death’ custom event has anything other than ‘destroy pawn’, my player character’s damage does not do anything to the enemy.

Here’s the pawn sensing code I have set up (Sorry it’s a little messy rn)

And here’s what I’m using to do damage (the missing node on the left is just a custom event node)

Here’s where I’m calling the death event

And here’s the actual death event

Bump

Hoping for an answer ;-;

There are quite a few timed nodes called like the delays and the AI Walk to. Even when your Death bool is set to true, any of these which were previously called will play through to their end unless there’s some means to abort them. By destroying the pawn you’d be cancelling any timed nodes.

AI Move to in particular is just going to execute until it succeeds or fails unless you call StopMovement on the AI controller.

You can access a pawns “Brain” though the ai controllers brain component. It has a couple of nodes regarding logic execution. You can Start, Stop & Restart Logic as well as poll if it is running or paused.

And if you want the pawn to stop in it’s track upon death you can also call “Stop Movement Immediately” on it’s movement component.

It seemed as though it was repeatedly firing off the logic even after finishing, repeating it even after the bool was set to true. But maybe I’m misunderstanding how it works.

I’ll give all this a go, thank you all so much! I’ll report back and see if any of this worked once I have time to give it a go.

Okay I did have a moment to test this right now so I did.

Stop movement immediately is something I’ve tried before, it didn’t seem to work either way but I tried it again along with stop logic (using stop logic afterwards). I’m still fairly new to coding this way so I’m wondering if I’m doing something wrong, but stop logic doesn’t seem to work at all nor does stop movement immediately.

I tried setting it up in various ways, both inside the logic loop to check each time it executes the logic, at the end of the loop, and at the very beginning of the loop as well as inside the death event. Nothing seems to be working.

AI Move to in particular is just going to execute until it succeeds or fails unless you call StopMovement on the AI controller.

I’ve tried to call stop movement in various ways, and as 3dRaven said I have also tried stopping the logic but nothing seems to be stopping this pawn from doing what it wants to do! lol

You can check a solution I made for picking up and dropping npc here

It has stop and reset logic for npc’s (you can pick them up and drop them)

You can also enable / disable the sensing directly

I have it set up similar to your pickup set up:

But when I test it I get an error “Blueprint Runtime Error: “Accessed None trying to read property BrainComponent”. Node: Stop Logic Graph: EventGraph Function: Execute Ubergraph BP Enemy Raccoon Blueprint: BP_EnemyRaccoon”

I also tried the other link, with the ‘SetSenseEnabled’ node but it needs a target and I’m not sure what that target is supposed to be (Sorry, I know real newbie here lol)

If I remember correctly you need a behavior tree running for the brain component to be initialized.

Ahh so it won’t stop the pawnsensing logic using stop logic.

Either time to start reading into behavior trees or find a way around this another way…

What is supposed to go on the ‘target’ section of SetSenseEnabled? I’m going to play around with that a bit before I dig into behavior trees as I know very little about them.

Also thank you very much for all this info!

edit
For now I’ll set your links as answered given this was basically the correct answer anyway. I’m just trying to do this without having to work with behavior trees yet.

The target would be the pawn sensing component inside of the ai pawn / character

Pawn sensing is the oldeer version. Epic later swapped it out with the ai perception component. (It would be added to the ai controller).

That has Set Sense Enabled in it that can toggle specific senses on and off.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.