I want to have a blueprint which always has a CapsuleComponent inherited.
Therefore I have a class , e.g Base which creates the CapsuleComponent in c++ in the constructor.
Now in the Derived class constructor I want to call the constructor of the Base, with Super::Base() to get the CapsuleComponent
You need to initialize the property first in the base, the following code is an example of how to initialize it in the base first
UCLASS()
class ABase : public AActor
{
GENERATED_UCLASS_BODY()
public:
UPROPERTY()
UCapsuleComponent* CapsuleComponent;
};
UCLASS()
class ADerived : public ABase
{
GENERATED_UCLASS_BODY()
};
ABase::ABase(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
CapsuleComponent = ObjectInitializer.CreateDefaultSubObject<UCapsuleComponent>(TEXT("CapsuleComponent"));
RootComponent = CapsuleComponent;
}
ADerived::ADerived(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
//CapsuleComponent is usable at this point
}
This is the convention, but the main issue is that you didn’t initialize the pointer property first.
Basically unless a property is private you can access it from any derived class.
Now if that property (or any regular variable) is a pointer you cannot access it without setting it to point at something.
In my base class I initialized the CapsuleComponent like you did in constructor and it is a public property. In my base class I was initializing the CapsuleComponent without using ObjectInitializer so I though just calling the base constructor would work.
I’m not understand what’s wrong fully but I’ll investigate and try your solution