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?
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)
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):