Hello.
I’m kinda new to UE4, and I’m a little confused about something, since it doesn’t seem to work the way I expected.
I have created 2 classes: “Enemy” and “Thief”. Enemy is a child of “Character” and “Thief” is a child of “Enemy”. Inside my “Enemy” class, I have the function “attack”, which I implement in the “Thief” class.
I also have a boolean variable in the “Enemy” class called “IsAttacking”, and I also have a Decorator for my “Thief” Behavior tree that checks if the thief is attacking by picking the value of this variable. So, if my thief is not already attacking, that means he can attack.
The thing is: I want to use this same decorator for other enemies behavior trees. I thought I could pick the “controlled pawn” and cast it to “Enemy”, so i can get the “IsAttacking” value, and then do the same to call the “attack” function, without ever knowing which child enemy class I’m telling to attack. This doesn’t seem to work, though, since the cast always fails.
I mean, I can cast “Pawn” to “Character”, but I can’t cast “Character” to my “Enemy” class, so I can acces this variable/function? Why? I thought I could do that since “Enemy” is a child of “Character”, and the Object referenced is a “Enemy” instance… (I’m thinking on the “Animal” to “Dog” cast example)