Preserving A Canvas Across Level Loads

I have a canvas that I am using as a loading screen of sorts (I am aware that Lumberyard has this functionality built in, and I didn’t like it…there is a black screen for approximately 5 seconds as the engine switches from the loading canvas to the main level). From my understanding, this is accomplished using this line:

UiCanvasBus.Event.SetKeepLoadedOnLevelUnload(self.entityId, true)

I have this line in the OnActivate() function on a script at the root of the UI canvas. The full code there is as follows:

	function canvasUnloadOnSignal:OnActivate()
GameLogger.LogInfoUrgent("Keeping level: " .. tostring(self.Properties.canvasName) .. " loaded on new level load.")
UiCanvasBus.Event.SetKeepLoadedOnLevelUnload(self.entityId, true)
local id = GameplayNotificationId(EntityId(), "CanvasUnloader_"..tostring(self.Properties.canvasName), typeid("string"))
self.eventConnection = GameplayNotificationBus.Connect(self, id)

(GameLogger logs the given string to a file) I can confirm that this is being called before the level is changed, and when I print out the value in the OnDeactivate() function it returns true.

Am I doing something wrong here? There is <1 second between the time that I set this flag and the level getting unloaded.

So, it turns out that this was actually working, but I was loading this canvas on an Entity using the UiCanvasAssetRef Component. When I switched to loading the canvas using the UiCanvasManagerBus in a Lua Script, everything stayed. The black screen is still there though between level loads, and I am not sure why.

Hi @Roosevelt.Boyland,

I’m not sure when your function canvasUnloadOnSignal:OnActivate is getting called. It should work if that is called after the canvas is loaded and before UiCanvasManager::DestroyLoadedCanvases is called (by the level unload). Normally we would set that flag as soon as the canvas is loaded.