void FWidgetBlueprintEditor::UpdatePreview(UBlueprint* InBlueprint, bool bInForceFullUpdate) { UUserWidget* PreviewActor = GetPreview(); // Signal that we're going to be constructing editor components if ( InBlueprint != nullptr && InBlueprint->SimpleConstructionScript != nullptr ) { InBlueprint->SimpleConstructionScript->BeginEditorComponentConstruction(); } // If the Blueprint is changing if ( InBlueprint != PreviewBlueprint || bInForceFullUpdate ) { // Destroy the previous actor instance DestroyPreview(); // Save the Blueprint we're creating a preview for PreviewBlueprint = Cast<UWidgetBlueprint>(InBlueprint); // Update the generated class'es widget tree to match the blueprint tree. That way the preview can update // without needing to do a full recompile. Cast<UWidgetBlueprintGeneratedClass>(PreviewBlueprint->GeneratedClass)->DesignerWidgetTree = DuplicateObject<UWidgetTree>(PreviewBlueprint->WidgetTree, PreviewBlueprint->GeneratedClass); PreviewActor = CreateWidget<UUserWidget>(PreviewScene.GetWorld(), PreviewBlueprint->GeneratedClass); PreviewActor->SetFlags(RF_Transactional); // Configure all the widgets to be set to design time. PreviewActor->SetDesignerFlags(GetCurrentDesignerFlags()); // Store a reference to the preview actor. PreviewWidgetPtr = PreviewActor; } OnWidgetPreviewUpdated.Broadcast(); }
FSCSEditorViewportClient::~FSCSEditorViewportClient() { // Ensure that an in-progress transaction is ended EndTransaction(); // Clean up the preview DestroyPreview(); }
void FWidgetBlueprintEditor::OnBlueprintChangedImpl(UBlueprint* InBlueprint, bool bIsJustBeingCompiled ) { DestroyPreview(); FBlueprintEditor::OnBlueprintChangedImpl(InBlueprint, bIsJustBeingCompiled); if ( InBlueprint ) { RefreshPreview(); } }
void FSCSEditorViewportClient::ToggleIsSimulateEnabled() { // Must destroy existing actors before we toggle the world state DestroyPreview(); bIsSimulateEnabled = !bIsSimulateEnabled; PreviewScene->GetWorld()->bBegunPlay = bIsSimulateEnabled; PreviewScene->GetWorld()->bShouldSimulatePhysics = bIsSimulateEnabled; AActor* PreviewActor = GetPreviewActor(); TSharedRef<SWidget> SCSEditor = BlueprintEditorPtr.Pin()->GetSCSEditor(); TSharedRef<SWidget> Inspector = BlueprintEditorPtr.Pin()->GetInspector(); // When simulate is enabled, we don't want to allow the user to modify the components UpdatePreviewActorForBlueprint(PreviewBlueprint, true); SCSEditor->SetEnabled(!bIsSimulateEnabled); Inspector->SetEnabled(!bIsSimulateEnabled); if(!IsRealtime()) { ToggleRealtimePreview(); } }
CTypefaceCombo::~CTypefaceCombo() { DestroyPreview(); }
void FSCSEditorViewportClient::UpdatePreviewActorForBlueprint(UBlueprint* InBlueprint, bool bInForceFullUpdate/* = false*/) { AActor* PreviewActor = GetPreviewActor(); // Signal that we're going to be constructing editor components if(InBlueprint != NULL && InBlueprint->SimpleConstructionScript != NULL) { InBlueprint->SimpleConstructionScript->BeginEditorComponentConstruction(); } // If the Blueprint is changing if(InBlueprint != PreviewBlueprint || bInForceFullUpdate) { // Destroy the previous actor instance DestroyPreview(); // Save the Blueprint we're creating a preview for PreviewBlueprint = InBlueprint; // Spawn a new preview actor based on the Blueprint's generated class if it's Actor-based if(PreviewBlueprint && PreviewBlueprint->GeneratedClass && PreviewBlueprint->GeneratedClass->IsChildOf(AActor::StaticClass())) { FVector SpawnLocation = FVector::ZeroVector; FRotator SpawnRotation = FRotator::ZeroRotator; // Spawn an Actor based on the Blueprint's generated class FActorSpawnParameters SpawnInfo; SpawnInfo.bNoCollisionFail = true; SpawnInfo.bNoFail = true; SpawnInfo.ObjectFlags = RF_Transient; // Temporarily remove the deprecated flag so we can respawn the Blueprint in the viewport bool bIsClassDeprecated = PreviewBlueprint->GeneratedClass->HasAnyClassFlags(CLASS_Deprecated); PreviewBlueprint->GeneratedClass->ClassFlags &= ~CLASS_Deprecated; PreviewActorPtr = PreviewActor = PreviewScene->GetWorld()->SpawnActor( PreviewBlueprint->GeneratedClass, &SpawnLocation, &SpawnRotation, SpawnInfo ); // Reassign the deprecated flag if it was previously assigned if(bIsClassDeprecated) { PreviewBlueprint->GeneratedClass->ClassFlags |= CLASS_Deprecated; } check(PreviewActor); // Ensure that the actor is visible if(PreviewActor->bHidden) { PreviewActor->bHidden = false; PreviewActor->MarkComponentsRenderStateDirty(); GetWorld()->SendAllEndOfFrameUpdates(); } // Prevent any audio from playing as a result of spawning if(GEngine->AudioDevice) { GEngine->AudioDevice->Flush(GetWorld()); } // Set the reference to the preview actor for component editing purposes if(PreviewBlueprint->SimpleConstructionScript != NULL) { PreviewBlueprint->SimpleConstructionScript->SetComponentEditorActorInstance(PreviewActor); } // Run the construction scripts again, otherwise the actor will appear as though it's had a script pass first, rather than the default properties as shown in the details panel PreviewActor->RerunConstructionScripts(); } } else if(PreviewActor) { PreviewActor->RerunConstructionScripts(); } // Signal that we're done constructing editor components if(InBlueprint != NULL && InBlueprint->SimpleConstructionScript != NULL) { InBlueprint->SimpleConstructionScript->EndEditorComponentConstruction(); } Invalidate(); RefreshPreviewBounds(); }