Hi,
I am having difficult referencing a variable from another actor BluePrint and am not sure why, other than that I am attempting to reference the variable of an array element (don’t know why that’d be an issue). The element is an actor BluePrint so that isn’t the issue.
The actor’s in the array are of the same class as this BluePrint (the same as “self”) so you can confirm from the picture that the referenced variable is typed correctly. The image below shows me being unable to “get” a variable from the array element actor BluePrint. I also cannot “set” variables from the array element in question (I tried just to be sure).
The next image is from a different project in which I refer to the variable of another actor BluePrint (in this case to set the variable). In this case to both the open BluePrint and the referenced BluePrint are of the same class.
as you can see it doesn’t have any problem.
Any explanation of why I cannot do what I am trying would be greatly appreciated. A solution would be more appreciated!
I think you don’t know what “self” means, it’s a reference to current instance of a class that code is currently executed in, it’s not blueprint, blueprint is a class same as C++ class, it’s a blueprint of object that yet to exist and all object based of that class will contain copy of that code and code of base classes (virtually) that you placed in that class and “self” is a instance of object in which this code is currently executed… but you not using “self” at all, instead you searching for “Planet” objects which is outside of current executed objects (but yes one of array elements will be planet in which code is currently executed in, in other words =self) and then call Get Owner function on all of planets, a function that returns Actor class object refrence, not planet (GetOwner | Unreal Engine Documentation) compiler at that point is not sure if object is made from class you trying to reference to it only knows it’s a Actor object and thats why you can only access Actor functions and varables, you need to convert it to class you trying to use, and to do that you need to use casting (“Cast to…” node) and when you casted to your class then you can refrence varables from that class.
The working example you showed works because “Spawn Actor” node is a specially coded node (based of UK2Node class) which makes output cast to class of object that being spawned automatically.
Go see “Class Viewer” and watch this it should open your eyes a little
The part about “self” I wasn’t confused about. But casting worked like a charm! Took me all of 2 seconds to fix the issue. Thanks so much!