scene:destroy() not firing

So, I’m building an app with multiple scenes and noticed that the destroy function isn’t firing when removeScene is called. I did some looking through the code and the forums to try and find something. That didn’t work. So, I decided to remove everything from the code but the bare minimum to test scene changes. I still can’t figure out why the destroy function isn’t working. If what I stated was unclear at all, I’d be more than happy to clarify, and any help is very appreciated. Here’s the code:

local composer = require( "composer" )

local scene = composer.newScene()


local function bark( )
	composer.gotoScene( "levels.gameOver", { time=800, effect="crossFade" } )
end

function scene:create( event )
	print("1")
	local sceneGroup = self.view
		

	local barkArrow = display.newRect(sceneGroup,display.contentCenterX, display.contentCenterY,40,40)
	barkArrow:addEventListener("touch", bark)
end

function scene:show( event )
	print("2")
	local sceneGroup = self.view
	local phase = event.phase

	if ( phase == "will" ) then

	elseif ( phase == "did" ) then
	end
end

function scene:hide( event )
	print("3")
	local sceneGroup = self.view
	local phase = event.phase

	if ( phase == "will" ) then

	elseif ( phase == "did" ) then
		composer.removeScene( "level1" )
	end
end

function scene:destroy( event )
	print("4")
	local sceneGroup = self.view
end

scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )

return scene

I just tested removeScene() and it did cause destroy() to be called.

Be sure your call to removeScene() is the same path as the call to loadScene()

Maybe you meant: composer.removeScene( "levels.level1" )?

See this old example (look at ifc/splash.lua):
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2022/07/composer_destroy.zip

Thank you so much! I changed it to composer.removeScene( “levels.level1” ) and it worked. I can’t believe I missed that lol!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.