You probably tried it and got ‘none’ errors. That’s because you hadn’t set the variable to the specific actor you want to use.
But, yes, it’s not scalable, because you have to manually set the variable for each type of actor you might interact with.
‘Get actors’ is fine, if it’s under control. IE you’re not doing it every frame. There is a ‘get actor of class’ node BTW, so you don’t need the array code.
The two final answers are
Have a reference to what you want to interact with, which you set when you spawn or introduce the object into the game.
Use blueprint interfaces. Then you can talk to anything you can get a reference to, without casting. You would probably get the reference from a dynamic process like a line trace.
If you have 2 classes, Food and Apple (deriving from Food), you can say these things in programming:
*Apple is a food.
*Food is not an apple.
If the Food class has a property “Taste”, Apple will have it too. Apple can declare a new property “Color” on itself which its parent class Food will not have. To access the Color property you need to cast whatever object reference you have to Apple.
Casting is like a question. Is this object an apple? a car? a person? and if so, you can use the result of the cast to access properties and methods which belong to it. You would not cast Apple to Food, because it is Food already. if the thing you cast is invalid (nullptr) it will fail the cast as well, being nothing.
Thank you for the reply! I did not know what the expose on spawn option existed, and I am learning still and trying to get a grasp on how to use interfaces but expose on spawn works great for now.