Day Sequence OnWorldCleanup resetting editor mode

Hello,

We’ve been seeing an issue where the editor mode would be reset after deleting a loaded Level Instance from the world.

I tracked it down to:

 	UnrealEditor-UnrealEd.dll!FEditorModeTools::ActivateDefaultMode() Line 750	C++
 	UnrealEditor-MovieSceneTools.dll!FSubTrackEditor::OnInitialize() Line 710	C++
 	UnrealEditor-Sequencer.dll!FSequencer::InitSequencer(const FSequencerInitParams & InitParams, const TSharedRef<ISequencerObjectChangeListener,1> & InObjectChangeListener, const TArray<TDelegate<TSharedRef<ISequencerTrackEditor,1> __cdecl(TSharedRef<ISequencer,1>),FDefaultDelegateUserPolicy>,TSizedDefaultAllocator<32>> & TrackEditorDelegates, const TArray<TDelegate<TSharedRef<ISequencerEditorObjectBinding,1> __cdecl(TSharedRef<ISequencer,1>),FDefaultDelegateUserPolicy>,TSizedDefaultAllocator<32>> & EditorObjectBindingDelegates, const TArray<TDelegate<TSharedRef<UE::Sequencer::IOutlinerColumn,1> __cdecl(void),FDefaultDelegateUserPolicy>,TSizedDefaultAllocator<32>> & OutlinerColumnDelegates, const TArray<TDelegate<TSharedRef<UE::Sequencer::IOutlinerIndicatorBuilder,1> __cdecl(void),FDefaultDelegateUserPolicy>,TSizedDefaultAllocator<32>> & OutlinerIndicatorDelegates) Line 751	C++
 	UnrealEditor-Sequencer.dll!FSequencerModule::CreateSequencer(const FSequencerInitParams & InitParams) Line 299	C++
 	UnrealEditor-DaySequenceEditor.dll!FDaySequenceEditorToolkit::InitializeInternal(const EToolkitMode::Type Mode, const TSharedPtr<IToolkitHost,1> & InitToolkitHost, const FSequencerInitParams & SequencerInitParams, TSharedRef<FDaySequenceEditorSpawnRegister,1> & SpawnRegister) Line 301	C++
 	UnrealEditor-DaySequenceEditor.dll!FDaySequenceEditorToolkit::InitializeActorPreview(const EToolkitMode::Type Mode, const TSharedPtr<IToolkitHost,1> & InitToolkitHost, ADaySequenceActor * InDayActor) Line 272	C++
>	UnrealEditor-DaySequenceEditor.dll!FDaySequenceActorPreview::EnablePreview(bool bEnable) Line 196	C++
 	UnrealEditor-DaySequenceEditor.dll!FDaySequenceActorPreview::Tick(float DeltaTime) Line 464	C++

It seemed a bit strange, so I looked into when the preview is re-created and spotted FDaySequenceActorPreview::OnWorldCleanup.

I’m not very familiar with the plugin, so was wondering if there’s a reason we’re clearing the preview regardless of the world that got cleaned up? The preview actor exists in our main world so I’m not sure if resetting the preview state when deleting a LI from the world makes sense. But since I could be missing something, I thought I’d reach out and ask.

I’m considering making the following change:

void FDaySequenceActorPreview::OnWorldCleanup(UWorld* World, bool bSessionEnded, bool bCleanupResources)
{
	if (!World || World->WorldType == EWorldType::Editor)
	{
		return;
	}

	const ADaySequenceActor* DaySequenceActorPtr = DaySequenceActor.Get();
	const UWorld* DaySequenceOwningWorld = DaySequenceActorPtr ? DaySequenceActorPtr->GetWorld() : nullptr;
	if (!DaySequenceOwningWorld || DaySequenceOwningWorld != World)
	{
		// No need to reset the preview state
		return;
	}
	
	EnablePreview(false);
}

Kind Regards,

Ivo

Steps to Reproduce

  1. Start the repro project.
  2. “ReproWorld” should be opened by default.
  3. Activate the “Modelling” editor mode(Shift+5).
  4. Select Level01 in the world outliner.
  5. Delete it.
  6. Observe that the editor mode is reset.

Hello Ivaylo,

I was able to reproduce this issue in a fresh UE 5.6.1 project without the Day Sequence plugin.

I am going to send a bug report in to Epic to get this inconsistency looked at, since this does not occur with the other editor modes if a level instance is deleted.

Thanks,

Kyle B.

Hi Kyle,

Thanks for the quick response.

I know it was resetting our custom editor modes and that was the first default mode I came across that let you delete actors from the world.

However, I didn’t realize it’s also happening without that actor so that’s quite interesting. Will try to dig into it further.

Kind Regards,

Ivo

Right, got the callstack for it and stems from:

// Removing levels from the world can happen either by entering/exiting level instance edit mode, or
 
// by using the Levels panel. The problem is that any temporary actors we may have spawned in the 
 
// level for visualization, gizmos, etc. will be garbage collected. While EdModeInteractiveToolsContext
 
// should end the tools for us, we still have to take care of mode-level temporary actors.
 
FWorldDelegates::PreLevelRemovedFromWorld.AddWeakLambda(this, [this](ULevel*, UWorld*) {
 
	// The ideal solution would be to just exit the mode, but we don't have a way to do that- we
 
	// can only request a mode switch on next tick.Since this is too late to prevent a crash, we
 
	// hand-clean up temporary actors here.
 
	if (SelectionInteraction)
 
	{
 
		SelectionInteraction->Shutdown();
 
	}
 
 
 
	// Since we're doing this hand-cleanup above, we could actually register to OnCurrentLevelChanged and
 
	// reinstate the temporary actors to stay in the mode. That seems a bit brittle, though, and there
 
	// is still some hope that we can someday exit the mode instead of having to keep track of what is
 
	// in danger of being garbage collected, so we might as well keep the workflow the same (i.e. exit
 
	// mode).
 
	GetModeManager()->ActivateDefaultMode();
 
});

From inside UModelingToolsEditorMode::Tick. I think this makes sense then. But at least our custom tools are not being cleared up now in the presence of the DaySequence Actor.

So I think this issue should be strictly about the Day Sequence Actor :slight_smile:

Hello Ivaylo,

I created a bug report for this issue that can be tracked here if/when it’s approved for public visibility: https://issues.unrealengine.com/issue/UE-332567

There is no ETA as priorities for bugs and features can shift at any time.

For now, I will close this ticket; if there’s any other information you come across feel free to share it here!

Thanks,

Kyle B.