void UActorComponent::BeginDestroy() { if (bHasBegunPlay) { EndPlay(EEndPlayReason::Destroyed); } // Ensure that we call UninitializeComponent before we destroy this component if (bHasBeenInitialized) { UninitializeComponent(); } ExecuteUnregisterEvents(); // Ensure that we call OnComponentDestroyed before we destroy this component if (bHasBeenCreated) { OnComponentDestroyed(); } World = NULL; // Remove from the parent's OwnedComponents list if (AActor* MyOwner = GetOwner()) { MyOwner->RemoveOwnedComponent(this); } Super::BeginDestroy(); }
void UActorComponent::DestroyComponent(bool bPromoteChildren/*= false*/) { // Avoid re-entrancy if (bIsBeingDestroyed) { return; } bIsBeingDestroyed = true; if (bHasBegunPlay) { EndPlay(EEndPlayReason::Destroyed); } // Ensure that we call UninitializeComponent before we destroy this component if (bHasBeenInitialized) { UninitializeComponent(); } // Unregister if registered if(IsRegistered()) { UnregisterComponent(); } // Then remove from Components array, if we have an Actor if(AActor* MyOwner = GetOwner()) { if (IsCreatedByConstructionScript()) { MyOwner->BlueprintCreatedComponents.Remove(this); } else { MyOwner->RemoveInstanceComponent(this); } MyOwner->RemoveOwnedComponent(this); if (MyOwner->GetRootComponent() == this) { MyOwner->SetRootComponent(NULL); } } // Tell the component it is being destroyed OnComponentDestroyed(); // Finally mark pending kill, to NULL out any other refs MarkPendingKill(); }