Why can we cast to Tower class like this?


This part I get it. In order to get the tank class, first I need to create a pointer pointing to Tank class in game mode.h, and then store the tank class in the pointer by using GameplayStatics::GetPlayerPawn(). . Therefore, I can acess the HandleDestruction() function in that class.

image
But this part I don’t get it and the system is also prventing me from compiling. Why don’t I need to repeat the process before? Why can I cast to Tower class from (DeadActor)? I think there is nothing in DeadActor class.

If that’s OK, why can’t I cast to Tank the same way like this?

Did you include the header for ATower?

You are? I’m a little confused.

Because it’s a pointer to an AActor and ATower derives from that.

DeadActor isn’t a class, it’s a variable of type AActor*

You can’t? Do you get any errors?

Thanks for replying. I got it. I was just lost in DeadActor and forgot I needed to pass DamagedActor in the paramater later on. That’s why it can be done like that.

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

Privacy & Terms