Hi, and sorry for my English
I have some issues trying to create a UShapeComponent dynamically from a inheritance structure.
Tha class diagram is:
The class MagneticComponent has the attribute UShapeComponent *geometry and its constructor is:
UMagneticComponent::UMagneticComponent(const class FObjectInitializer &objectInitializer)
:Super(objectInitializer),
geometry(objectInitializer.CreateDefaultSubobject<UShapeComponent>(this,UMagneticComponent::geometryComponentName))
{
}
And the class is UCLASS(abstract, ConversionRoot).
The child’s class from this class set the geometry how it want, like:
UMagneticSphereComponent::UMagneticSphereComponent(const class FObjectInitializer &objectInitializer)
:Super(objectInitializer.SetDefaultSubobjectClass<USphereComponent>(Super::geometryComponentName))
{
}
After, the classes StaticObject and DynamicObject, both of they are like UCLASS(abstract, ConversionRoot), have attribute like UMagneticComponent *magnetic, and their constructors are like:
AStaticObject::AStaticObject(const class FObjectInitializer &objectInitializer)
:Super(objectInitializer),
magnetic(objectInitializer.CreateDefaultSubobject<UMagneticComponent>(this, AStaticObject::magneticComponentName)),
{
}
And the child classes create the specific magnetic component in their constructors, like:
AStaticSphereObject::AStaticSphereObject(const class FObjectInitializer &objectInitializer)
:Super(objectInitializer.SetDefaultSubobjectClass<UMagneticSphereComponent>(Super::magneticComponentName))
{
}
This code works fine in the editor, but if I try to make a build/launch or use the debug, crash creating UMagneticComponent and I don’t understand why.
Am I missing something? is it possible use a structure like this?
Thanks all for the help.