Hello Unreal Community,
I’m new to C++ programming any advice or examples of my question would be very appreciated.
I have 2 classes, - Class A extend Pawn and - Class B extend Actor.
I’ve created a function in Class B (Actor) and in trying to call that function from Class A (Pawn);
Is this possible?
I tried few Methods which can Compile but when start Play - UE4 Crash.
Calling functions from another class by including the class in your current one should be fine. Some of the other stuff you’re doing is a little strange, though.
First, as far as I know, you don’t need to include things that are in the base engine code, e.g. the kismet library. As an aside, the kismet library is mostly for blueprints and BP nodes, as far as I know. They’re usually just C++ functions wrapped in another function.
Second, compiling just means you don’t have any syntactic errors. There can still be a number of problems with your code, especially in the case of null pointers. It would be helpful if you posted your crash report, but I’m guessing it has to do with that. The issue I see is your setting of BaseShip. GetClass(), if I remember, just returns the class of the passed object. It looks like you want to create a new AMainShip object. To do that, check out this link.
Last, I’m not entirely sure you want to do that, either, though. Is the ship supposed to be your main character- the thing you play as in your game? If so, you should probably either place an instance of the actor into your actual level and possess it or make a spawn point and set the ship as your default actor.