`scene:show` not firing after first time using `composer.gotoScene()`

Hi everyone,

I’m encountering a strange issue with Composer scene transitions in Solar2D.

I’m navigating to a scene called "sceneSalaEspera" using:

composer.removeHidden()
composer.gotoScene("sceneSalaEspera", "fade", 200)

What works:

  • The first time I go to the scene, both scene:create() and scene:show() are triggered correctly.
  • The log output looks like this:
20250417-22:44:55>>> INFO - sceneSalaEspera - create - create - event:  - {"name":"create"}
20250417-22:44:55>>> INFO - sceneSalaEspera - show - show - event:  - {"name":"show","phase":"will"}
20250417-22:44:55>>> INFO - sceneSalaEspera - show - show - event:  - {"name":"show","phase":"did"}

The issue:

  • On subsequent visits to the scene, only scene:create() is triggered.
  • scene:show() is never called.
  • The log output for the second call is:
20250417-22:45:45>>> INFO - sceneSalaEspera - create - create - event:  - {"name":"create"}

So far I’ve made sure that:

  • The scene is not currently visible.
  • composer.removeHidden() is called before gotoScene, to force a clean load.

Scene code:

Here’s how the scene is defined:

-- create()
function scene:create( event )
    utils:log("INFO","sceneSalaEspera", "create", "create - event: ", event)

    local pantallaSalaEsperaGroup = self.view
    pantallaSalaEsperaGroup.background = display.newImageRect( pantallaSalaEsperaGroup, "fondoVerd.png", 694, 360 )
    pantallaSalaEsperaGroup.background.x = _W
    pantallaSalaEsperaGroup.background.y = _H
end

-- show()
function scene:show( event )
    utils:log("INFO","sceneSalaEspera", "show", "show - event: ", event)

    local pantallaSalaEsperaGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        pantallaSalaEsperaGroup.pantallaSalaEsperaText = display.newText(
            pantallaSalaEsperaGroup,
            "Esperant als rivals...",
            _W,
            _H - 30,
            native.systemFont,
            20
        )

    elseif ( phase == "did" ) then
        -- Code here runs when the scene is entirely on screen
    end
end

Question:

Has anyone else experienced this? Is there something I’m missing about how Composer handles the scene lifecycle after the first visit?

Any tips would be very appreciated. Thanks a lot in advance!

I think the scene must be removed to trigger show event again

removeScene

Hello Jordi74,

Welcome of the Solar2D community! I would agree with you on removing hidden scene before gotoScene, but I am not able to see where the problem lie.

I have attached here an example, originally shared by “bgmadclown”, with slight modification. The example only includes 3 lua files, main, game scene and a transition scene. You may want to take a look on the lifecycle change of the scenes in this example.
example.zip (1.8 KB)

I hope this helps. Thank you.

1 Like

Hi @Jordi74 , welcome!

Since I don’t have a sample code, I’m not entirely sure but I believe your use of composer.removeHidden() might be causing the issue.
I’d suggest using composer.removeHidden() right after you load the new scene so it " Removes or recycles all scenes except for the currently active scene.", instead of using it before composer.goToScene(). See Scene Management:

Here is a sample code:

function scene:show( event )
    local phase = event.phase

    if ( phase == "will" ) then

    elseif ( phase == "did" ) then
        -- THIS IS THE IMPORTANT PART
        -- New scene is loaded so I can now safely remove inactive scenes
        composer.removeHidden()

        -- Do stuff
    end
end

Can you try it and tell if it works?