Search Unity

Resolved Need help creating a pause menu that persists between scenes

Discussion in 'Prefabs' started by FrancDays, May 1, 2021.

  1. FrancDays

    FrancDays

    Joined:
    May 1, 2021
    Posts:
    3
    I'm having trouble making a working pause menu that can be loaded on any scene. To do that, I've made a prefab that gets loaded on an initial scene, and all of the objects inside of it are subject to DontDestroyOnLoad, thus persisting between scenes. However, when I tried to use these menus, more specifically, an inventory menu, the scrollbar doesn't work, and I can't scroll through the list. I suspect this is due to some issues with the EventSystem.

    This is the prefab (the image components are just there to fill the content):

    upload_2021-5-1_17-39-12.png

    This is the scene being loaded:

    upload_2021-5-1_17-40-20.png

    Upon running, this is the result:

    upload_2021-5-1_17-41-46.png

    upload_2021-5-1_17-42-13.png

    Clicking and dragging the scrollbar does nothing, and using the scrollwheel does nothing either. I have tried to move the EventSystem around - I put it in the prefab whilst deleting it from the original scene, and I tried having it in the scene with none in the prefab as well (this scenario here). Any way to fix this?
     
  2. Marc-Saubion

    Marc-Saubion

    Joined:
    Jul 6, 2011
    Posts:
    655
    Did you try having an event system in the menu prefab?
     
  3. FrancDays

    FrancDays

    Joined:
    May 1, 2021
    Posts:
    3
    I did, it was one of the two ways I tried this. I tried having an EventSystem in the scene, and none in the prefab, and vice versa, with the EventSystem in the prefab, and none in the scene. Having both has Unity complain that there shouldn't be two EventSystems upon execution.
     
  4. Marc-Saubion

    Marc-Saubion

    Joined:
    Jul 6, 2011
    Posts:
    655
    I guess you'll have to try it with a prefab containing only a default scroll view and see if the issue is there from the start or if you set something wrong somewhere.
     
  5. FrancDays

    FrancDays

    Joined:
    May 1, 2021
    Posts:
    3
    I tried creating a separate prefab, just for the pause menu, and loaded it the same way as the other objects. After a slight change in the script so it would load both prefabs (otherwise it would only load one of them), seems like having the prefabs separate works like a charm. The inventory scroll works, and it persists between scenes!

    With the issue now resolved, I'll just mark this thread as resolved. I suspect the problem wasn't due to the EventSystem after all, but probably due to the way I had the canvas set up.
     
    Marc-Saubion likes this.