[4.7.6]OI.DoNotCreateDefaultSubobject not working

TestPickup.h and .cpp

class SOME_API ATestPickup : public APickup
...
ATestPickup::ATestPickup(const class FObjectInitializer& OI)
	: Super(OI.DoNotCreateDefaultSubobject("ItemDestroyableComponent"))

Pickup.cpp //end of constructor

RootComponent = collision_component;
destroyable_component = OI.CreateDefaultSubobject<UItemDestroyableComponent>(this, "ItemDestroyableComponent");
....

LogClass:Warning: Ignored DoNotCreateDefaultSubobject for ItemDestroyableComponent as it’s marked as required. Creating ItemDestroyableComponent.

Using other function works.

destroyable_component = 
	Cast<UItemDestroyableComponent>(PCIP.CreateDefaultSubobject(
	this,
	"ItemDestroyableComponent",
	UItemDestroyableComponent::StaticClass(),
	UItemDestroyableComponent::StaticClass(),
	false, false, false));

This didn’t help me. However I found something else that worked.

UMyObject::UMyObject()
{
	auto* MyComponent = Cast<UActorComponent>(GetDefaultSubobjectByName("ComponentNameSpecifiedInBaseClass"));
	if (IsValid(MyComponent))
	{
		RemoveOwnedComponent(MyComponent);
		MyComponent->DestroyComponent();
	}
}

To not have this warning

LogClass:Warning: Ignored DoNotCreateDefaultSubobject for ItemDestroyableComponent as it’s marked as required. Creating ItemDestroyableComponent.

default subobjects must be created using CreateOptionalDefaultSubobject instead of the CreateDefaultSubobject, however you have to be able to modify the source of the class you’re willing to remove the default subobjects from.

Hopefully it helps someone else as well.

1 Like