Weird behavior with booleans

i’m using a boolean to detemine if the player is hiding or not, the booleans is set to true when hidden and false when not hidden, but when I print the state of the boolean in event tick it looks like it’s being set to true and false everyframe, and I don’t know why this is happening, I’ve already checked where the bool is being set and right now there is only 2 setters and 3 getters. could someone help.

Annotation 2021-07-21 220241
Annotation 2021-07-21 220153


Can you show the whole of Hide and Unhide and where they are called from?

they’re called on a key press
Annotation 2021-07-21 221143

other people have had a similar problem
https://answers.unrealengine.com/questions/886305/odd-behavior-when-checking-bool-with-tick-event.html

Can you show the whole of Hide and Unhide?

those functions just change the collision and the visiblity of the player they’re not doing anything with the boolean. and the weird thing is that the hide and unhide work with no problem, the problem is when i want to reference this bool to change the behavior of my ai and that’s where it breaks.
i actually lloked it up and some people have had this problem aswell so maybe it’s bug in the engine?

i actually lloked it up and some people have had this problem aswell so maybe it’s bug in the engine?

If you read the post you linked, you’ll find out it was them messing it all up… So maaaaybe it’s the script? :wink:


Let’s say you’ll start relying on the FlipFlop inside a function. And now you’re in The Debug Hell because the value goes out of scope rather quickly.

i’ve had this problem in the past too, and i asked so many people about it but there was no solution to it. i ended up using a flip flop to do what i needed, another time i had to delete the variable and re create it and that fixed it, but this time it doesn’t work.

Hi,

(1) to which class does your boolean “IsHiding” belong, so is it a variable of “Bed” or of “MainCharacter”?

(2) on which tick do you print it? In the tick of the “Bed” class?

(3) how many “Bed” objects do you have in your world?

Cause it seems like you have a “MainCharacter” class and a “Bed” class and the “IsHiding” seems to be inside the “Bed” class, not inside “MainCharacter”.

the variable belongs to the bed class and i’m printing it in the bed class itself. the character doesnt have anything to do with this variable. and there’s 3 instances of this class in the world

i think i know where the problem might be, is it because i have 3 instances in the world and each one prints diffrent instances of that boolean? cuz i see 1 true and 2 false

1 Like

Yes, that’s it. That’s what I was going to say.

Don’t use FlipFlop inside a function. Use something like this:

image

i have 3 instances in the world and each one prints diffrent instances of that boolean

Yeah, that’d be it! :smiley:

1 Like

but how i’m i supposed to find the right instance cuz with the code i have right now it doesn’t seem to work.

What are you trying to find? The bed the character is hiding under?

  • there’s should be no reason ever to run Get All Actors unless you really need to do something to all actors
  • if the player starts hiding under the bed, store the reference to that bed in the player - then there’s no need to search or set any variables

The AI can ask the player.

1 Like

yes the ai needs to know which bed hes hiding under

Think about the action required for the player to hide under the bed - how does it happen? Do we click on it? Bump into it? Is it randomly assigned (maybe it’s a puzzle game)?

The AI can ask the player.

I would actually broadcast it loud and clear and the AI gets to choose whether to act on it or not. Smoke and mirrors. All the way. Fake it until it breaks :wink:

regardless of what the ai is supposed to do, i wanna know why the code i’m using isn’t working, i loop through all the instances with a for each loop and check if is hididng is true, and as soon as i find the right one it should break the loop and do the rest of the code.

But you do not do anything when you break the loop. At least we can’t see that. Perhaps you do it before you break it? We can’t see that either!

the rest of the code is just setting blackboard keys and then going to the break pin as u can see above. it wouldn’t break it if it doesn’t find the right instances.