# How to make a bool change only when two other bools are both true or both false?

**URL:** <https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [November 24, 2023, 7:01pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756 "2023-11-24T19:01:25Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![fael097](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fael097/32/250778_2.png) [@fael097](https://forums.unrealengine.com/u/fael097)\
**Post date:** [November 24, 2023, 7:01pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756/1 "2023-11-24T19:01:25Z")

</div>

I want to check if an actor is fully on screen by checking if a point on top of the head and at its feet are on screen.

This works for one point:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/c/4/0c4988d3780b0af593cf7ded4823b16e99af7249.png)

However, this doesn’t work for both points, as it returns true if both are true, but false if only one is false:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/3/5/d350db1bdc9ce9c3037d44f0cb331638b77c8b10.png)

How to make it change bool value only when both values change?

---

<div class="post-metadata">

**Author:** ![Leomerya12](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/leomerya12/32/926321_2.png) [@Leomerya12](https://forums.unrealengine.com/u/Leomerya12)\
**Post date:** [November 24, 2023, 7:29pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756/2 "2023-11-24T19:29:06Z")

</div>

I’m slightly confused, because your goal is to determine if the character is on-screen.

The way that the character is determined to be on-screen is if BOTH values (top and bottom) are TRUE.

Therefore, if any one of them is FALSE, then then the entire function should be FALSE.

So… what is it that you want? For the function to only return FALSE if BOTH are FALSE? (Only after both are TRUE?)

I just need to be clear on that.

EDIT: If so-

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/e/4/7e4c5e5a6746ffa3fd08289fc9703c5b8a0200d3.jpeg)

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [November 24, 2023, 7:41pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756/3 "2023-11-24T19:41:05Z")

</div>

If you want something to CHANGE then you need STATE.  
So, you need to store a `CalculatedVisibility` boolean in the object.  
Then, you need to update that `CalculatedVisibility` if both of the other booleans change.

The easiest way to do this is to create an `UpdateCalcuatedVisiblity` function.  
Inside this function, check whether each value is different from the `CalculatedVisibility`.  
If _both_ values are different from the `CalculatedVisibility` then you flip the value of `CalculatedVisibility`. You can do this with two `Branch` nodes an a `Set` node that reads the value and passes it through `NOT`

When you then need to actually use this value, simply read the `CalculatedVisibility` boolean.

That being said – it seems unlikely that the behavior you _say_ you want, is actually what you want. Try it, and if it doesn’t do what you expect it to, then maybe step back and describe in a little more details what rules you actually want to enforce.

(For example, what do you want if the “center of the mesh” is below the screen, but the “center of the head” is above the screen? Neither will be “on screen” but a bunch of … stuff … would be “on screen” if rendered.)

---

<div class="post-metadata">

**Author:** ![fael097](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fael097/32/250778_2.png) [@fael097](https://forums.unrealengine.com/u/fael097)\
**Post date:** [November 24, 2023, 8:10pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756/4 "2023-11-24T20:10:21Z")

</div>

I want to know when the character enters or leaves the screen completely

I was kinda expecting something way simpler, like a logic gate i didn’t know of, or something.

here’s what I did:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/2/b/d2bceb89d9d9dac4e7ae2cbf3dd30f9acd04c484.png)

---

<div class="post-metadata">

**Author:** ![Leomerya12](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/leomerya12/32/926321_2.png) [@Leomerya12](https://forums.unrealengine.com/u/Leomerya12)\
**Post date:** [November 24, 2023, 8:20pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756/5 "2023-11-24T20:20:12Z")

</div>

You may be complicating this.

I’m reading:

1. If “Top\_Of\_Character” on-screen value EQUALS “Bottom\_of\_Character” on-screen value, proceed to next evaluation, else, test again.

2. If “Been\_Fully\_on\_Screen” value does NOT EQUAL “Top\_of\_Character” on-screen value, SET “Been\_Fully\_on\_Screen” to _unknown value_ (TRUE?) THEN set “Fully\_On\_Screen” to TRUE, else, test again from start.

EDIT: My question is where do you reset the “Fully\_on\_Screen” and “Been\_Fully\_on\_Screen” values?

---

<div class="post-metadata">

**Author:** ![MX1RXINC](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MX1RXINC](https://forums.unrealengine.com/u/MX1RXINC)\
**Post date:** [November 24, 2023, 8:22pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756/6 "2023-11-24T20:22:02Z")

</div>

It sounds like a de-spawning logic would be apropriate and much more optimized.

---

<div class="post-metadata">

**Author:** ![Leomerya12](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/leomerya12/32/926321_2.png) [@Leomerya12](https://forums.unrealengine.com/u/Leomerya12)\
**Post date:** [November 24, 2023, 8:22pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756/7 "2023-11-24T20:22:39Z")

</div>

Ah, I agree!

---

<div class="post-metadata">

**Author:** ![fael097](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fael097/32/250778_2.png) [@fael097](https://forums.unrealengine.com/u/fael097)\
**Post date:** [November 24, 2023, 8:32pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756/8 "2023-11-24T20:32:35Z")

</div>

Default value for “onscreen” = false.

1 - If top of char and bottom of char are equal (so both on screen, or both not on screen) do 2, else out whatever “onscreen” was already set to.  
2 - if top of char is different from whatever “onscreen” was already set to, then set value of “onscreen” to the same as itself, else out whatever “onscreen” was already set to.

how is this complicated? 😅

I mean it already works. I was just wondering if it could be even simpler, like without those branches.

I don’t need to reset the value, just update whenever it changes

---

<div class="post-metadata">

**Author:** ![fael097](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fael097/32/250778_2.png) [@fael097](https://forums.unrealengine.com/u/fael097)\
**Post date:** [November 24, 2023, 8:32pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756/9 "2023-11-24T20:32:45Z")

</div>

What’s that?

---

<div class="post-metadata">

**Author:** ![Leomerya12](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/leomerya12/32/926321_2.png) [@Leomerya12](https://forums.unrealengine.com/u/Leomerya12)\
**Post date:** [November 24, 2023, 8:34pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756/10 "2023-11-24T20:34:52Z")

</div>

Then I misunderstood you. I thought you meant it DOES NOT work.

---

<div class="post-metadata">

**Author:** ![ShinyLopunny69](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ShinyLopunny69](https://forums.unrealengine.com/u/ShinyLopunny69)\
**Post date:** [November 24, 2023, 10:03pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756/11 "2023-11-24T22:03:01Z")

</div>

The logic gate you were looking for is XOR. It returns false if both are true or both are false.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [December 24, 2023, 10:03pm UTC](https://forums.unrealengine.com/t/how-to-make-a-bool-change-only-when-two-other-bools-are-both-true-or-both-false/1417756/12 "2023-12-24T22:03:39Z")

</div>

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