"Integer + Integer" is evaluated twice, first time?

Starting from the TwinStick blueprint template, I made an Actor blueprint with a Sphere and an EntryCount integer variable (with default value 0). I made an event graph for ‘Actor Begin Overlap’ which increments EntryCount and shows it with Print String. The first time the player enters the sphere, the value ‘2’ is printed (I expected ‘1’). The second time, ‘3’ is printed, then ‘4’ and so on - so it appears the first time the event happens, the counter is incremented twice (incorrectly, as far as I can tell), then every subsequent time it is incremented once (correctly).

The two links from the output of ‘Integer + Integer’ seem significant (if I set EntryCount, then have ‘Print String’ get EntryCount (instead of reusing the output of ‘Integer + Integer’), then I get expected behavior: but it seems like what I’m doing should work either way?

Hi barrettcolin ,

It’s not really that it’s evaluated twice, it’s that print string will always be 1 more than the int value since it’s connected to the + node.

So the flow looks like something like this

Entry = 0

…Event happen

…Entry =Entry + 1

…Print value of Entry +1 (2)

Entry = 1

…Event happen

…Entry = Entry + 1

…Print value of Entry + 1 (3)

Entry = 2

Change your blueprint to something like this and you’ll get the expected behavior

http://s17.postimg.org/b4r8gjmcv/int.png

No, what you are seeing is not a bug.
It’s a feature!

Look at the orders of execution.
FIRST you increase the variable, and THEN you print something, but the Input for that is again “EntryCount + 1”.

You can think of it like this:
Only the white “Exec” lines are relevant for the order of execution.
If you provide an input (like “In String” for “Print String”), it traces the given path back.

So it’s like this:

  • Receive Event

  • Set “Entry Count” to “Entry Count + 1” (e.g.: Assign 0 + 1 = 1 to EntryCount)

  • Print String: []

  • Trace everything back to “Entry Count”

  • Increase the retriven value by 1 (e.g.: Retriven value = 1 + 1 = 2)

  • Convert to string

  • Print String: [2]

If you first exec Print String, and THEN increase the value, you get the correct behaviour - However you will calculate 1+1 twice. That’s why increasing the variable and then GET it again is the way to go in my opinion. Also it will be easier to read, because it will be obvious that you want to log the value of Entry Count (and not “EntryCount + 1” or something like that)

Actually, in my graph it is really that ‘Integer + Integer’ is evaluated twice - once for the ‘Set’, then again for the ‘Print’. My mistake was thinking that once a part of the graph had been evaluated, it would stay evaluated (which is to say, that I could reference the output of ‘Integer + Integer’ in two places and it would only be calculated once)

Yes, excellent explanation, thank you; I had a basic misconception for how the input evaluation worked.

Yes sorry I was not clearer, I meant to say that the + node will be evaluated twice, but the value of Entry count would not be set again.

Every time an input value is connected, it’ll run the left part of the graph to evaluate it’s value, thus the + node being executed again.

But I understand that you understand that now :slight_smile:

Cheers,

  • Marc

You are right about the change, btw - I had already done that, I wrote about it in the last paragraph. Thanks for the screenshot!

Thanks to MarcAndreG and holzlag0r for their help: turns out the graph should look like this (and I totally endorse best practice being to add a new ‘Get Entry Count’ node instead of reusing the existing one, but for completeness):

No problem!
If you want you can mark it as a correct answer. (: