Hey,
I’ve got a component that is attached to a Pawn. The component has an array of (bone-)names. I’ve overriden the PostEditChangeChainProperty() method to react when a new item is added to the array ( in the details panel) .When a new item is added I’d like to create and add a component to the component’s owner, like when clicking the “Add Component” button in blueprint.
I’ve tried the following
#if WITH_EDITOR
void MyComponent::PostEditChangeChainProperty(struct FPropertyChangedChainEvent& PropertyChangedEvent) {
if (PropertyChangedEvent.ChangeType == EPropertyChangeType::ArrayAdd) {
UBoxComponent* box = ConstructObject<UBoxComponent>(UBoxComponent::StaticClass(),GetTransientPackage(),BoneNames.Last());
GetOwner()->AddOwnedComponent(box);
}
Super::PostEditChangeChainProperty(PropertyChangedEvent);
}
#endif
It crashes at GetOwner() due to nullptr.
What’s the proper way of doing it?
Edit:
I’ve found the desired method as
FKismetEditorUtilities::AddComponentsToBlueprint(UBlueprint* Blueprint, const TArray<UActorComponent*>& Components, bool bHarvesting, USCS_Node* OptionalNewRootNode, bool bKeepMobility /*= false*/)
But how do I get the UBlueprint pointer to the component’s owner?