How to get var from array element in for loop?

Hi, so in my Player controller I have an array of actors, and each actor have a boolean var. I want to check, for each element, if it’s var is true or false. But I can’t find the “get var” node from the for loop. any advice?

I can’t see the var from the “Array element” exit.

Edit: “selectedUnits” array is defined as an array of actor type “Ally Generic”, which has said bolean var. Yet like I said I can’t find the “get” node for the var, pulling from the Array element exit.

1 Like

If it’s an array of actors, you need to cast to the appropriate blueprint type before looking for the variable.

1 Like

Edit :slight_smile:

That should work then, if it’s the correct type…

1 Like

Weirdly it doesn’t. I am not using any cast, but the Array is of the correct type. Could you elaborate on how to solve this using cast? I’il like to try that as well. And thanks!

If the array is of type ‘reference to Ally Generic’, then it should work.

If the array is of type ‘reference to actor’, then you need to pull that element pin, and search for ‘cast to’ your blueprint type. Then you can access the variable.

Ah, did you make the foreach loop node fresh, after changing the variable type?

You always need to make new nodes by dragging, if you try and re-use old nodes it will lead to confusion…

1 Like

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