Problem in Casting

Hi can anybody help me to understand this problem .

I have 2 class one is Actor class and Another is ActorComponent class. When I try to cast from Actor class to ActorComponent class I can able to access its method but I when trying to access the ActorComponent Variables the Unreal engine crashes. But same task if I do with Actor class to Actor class everything is fine but why the Actor to ActorComponent cast is crashes the unreal! 1|690x330

Because GetPawn returns the controlled pawn which is not a UActorComponent let alone your derived class, so the cast will fail and will return nullptr.

You then dereference that null pointer which is undefined behaviour and the reason for your crash.

Privacy & Terms