The messsage still appears though even if the array is empty. It does go away when I break the link from “GET” to Select Vector (just to make sure the message doesn’t come from an entirely different place). So I’m wondering how is that possible? Is it normal behaviour that both values of a “Select” are calculated no matter the condition? Or am I just not thinking straight?
yes, you are right. blueprint will try to put as much stuff in one go instead of making them multiple instructions.
So you need to check if your length > 0 with a branch node and then decide what to do next.
Having real trouble getting this to work any other way. I’ve skimmed over my other blueprints and it’s a bit scary to know that the Select nodes evaluate all cases all the time. This is so counter to what we’re used to in programming and sounds horrible for performance. It’s the first thing in blueprints that makes me want to go writing code instead. Surely there is a technically sound reason for this, but still.
it’s not a strange behavior, think of select node a ?: one line branch function.
You should be glad that you run into this early on instead of much later.
ie.
len > 0 ? array[0] : null
this will evaluate both array[0] and null ready for return(usually they also assume true branch is the more likely branch to run into).
It’s the same like the following condition that many does it wrong.
if length(array)>0 and array[0]!=null :
both will be evaluated and if array is empty or not allocated, you get exceptions or seg fault.
So, make sure you don’t trip over those obvious things and be careful for those nodes that accepts conditional inputs.
Personally I wouldn’t worry about it. You’ve put steps in place to ensure its not trying to use a null index so should affect what your trying to do.
However one possible option is adding an index at 0 when its empty which would be your 0,0,0 and get index 0 instead of using the select. You can then clear the array after you’ve used it.
I put steps in place that don’t work What’s happening is that LastIndex returns -1 because the array is empty and then the BP is trying to access array-1] because of this odd behaviour. Granted, the array can never be null but it’s still ugly anyway especially since that stuff runs per Tick whenever the player is moving.
Thought about putting a “bumper” item into the array too. It would work, what an ugly hack though. Guess I’ll end up doing that.