Questions in Turret class

Apoloy in advance. I am very new to unreal and cpp. The questions might be silly…

  1. In PawnTurret.h,
APawnTank* PlayerPawn;

why we don’t need to set nullptr to it here? Is it necessary to everytime intialize a pointer as nullptr?

  1. In PawnTurret.h and cpp,
    why we don’t need to declare the PawnTurrent class and define it in cpp like what we do for tank?
public:
	APawnTurret();
APawnTurret::APawnTurret() 
{
    
}
  1. It’s going to be set to something as soon as the game begins so it’s not really needed.
  2. Do you mean the other way round? As in have APawnTurret in APawnTank? What you are saying right now is why doesn’t APawnTurret have a pointer to an instance of the same class (APawnTurret).

In PawnTank.cpp, it has:

APawnTank::APawnTank()
{
    SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
    SpringArm->SetupAttachment(RootComponent);

    Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
    Camera->SetupAttachment(SpringArm);


}

and in its header file, it has APawnTank(); in the public.
Does this mean it is creating an instance of the PawnTank class?

In PawnTurret, why we don’t need it?

No that’s the code that will run when an instance of APawnTank is created which is to create those two extra components.

APawnTurret doesn’t have that because it’s not doing anything extra. What is done in the base class is all that is needed.

2 Likes

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

Privacy & Terms