Can Super() ref a grandpa class?

I need make a tankvehicle class from AWheeledVehicle but skip its constructor body since it hardcode a 4-wheel movementcomponent creation, so I want super(ObjectInitializer) get me APawn not AWheeledVehicle. I remember it’s possible in udk’s script but I’m really new to cpp. Any one help? plz.

Or, anyone has better solution with diy vehicle&movementcomponent workflow I’d love to learn.

Hi and welcome to the forums! I have no experience with vehicles, but I’ve taken a quick look at the source and found something that might help. Firstly I would recommend against trying to skip parent class constructors.

I’ve taken a look at WheeledVehicle.cpp and the spawning of the 4 wheels happens not here directly but in the constructor of WheeledVehicleComponent4W. There are two things you could try now:

  • Inside your tank vehicle class’ constructor access the VehicleMovementComponent and try to change the number of wheels there. Its already setup for 4 wheels, but you may adding or removing wheels now may work because the 4 wheels are just a list of data at this point.
  • Replace the VehicleMovementComponentwith a fresh one and do the wheel setup from there.

On how to set the number of wheels, look at the constructor in WheeledVehicleComponent4W.cpp.

No. You need to call each step of the constructor hierarchy or you’ll have some undesirable initialization issues.

What you can do instead is use the object initializer to omit creation of the default components you don’t want. FObjectInitializer has a bunch of override functions for controlling components, namely DoNotCreateDefaultSubobject. Since you’re acting on base class components, it’s a bit different from using it on your own class, but it’s fairly straightforward:

AMyFancyWheeledVehicle::AMyFancyWheeledVehicle( const class FObjectInitializer& ObjectInitializer )
	: Super( ObjectInitializer.DoNotCreateDefaultSubobject( AWheeledVehicle::VehicleMovementComponentName ) )

The argument for DoNotCreateDefaultSubobject or other overrides is the name of the component, but classes like AWheeledVehicle and ACharacter have specifically been built with the possibility of these overrides in mind, so said name is exposed as a variable.

to cmartel: Oh yes DoNotCreateDefaultSubobject, self explaining. Thanks a lot.

to NisshokuZK: Problem is even you make a new moveComponent class the vehicle constructor still use component4W as default, so the only way is modify component4W which I try to avoid. I might modify engine in final dev stage. Btw making tanks is a little more complicate than adding wheels, need change some physx classes, here and there, no big deal though.

before see your help I just brutally recreated the movecomponent in my vehicle constructor and it works… Thanks again!

See this tutorial here.

This is how you can instruct a base class to use a different component class for a particular named component. The following should be what you want, I think:

: Super(ObjectInitializer.SetDefaultSubobjectClass<UMyVehicleMoveComp>(AWheeledVehicle::VehicleMovementComponentName))

Yes that’s the right way thanks!