Worlds - Changing Level Menu in Scene

Help, support and information for our Game Framework Unity Asset.
If posting about the assets in the extras bundle then please use the appropriate forum.
Post Reply
tenfiddy
Posts: 24
Joined: Wed Jul 24, 2019 9:02 pm

Worlds - Changing Level Menu in Scene

Post by tenfiddy » Tue Aug 27, 2019 3:32 pm

This is for my VR Game...

I have hit another roadblock.

I am trying to change the world / levels in the same scene. I would like to click on the new world and then refresh the levelbuttons to match the new world levels. Currently - when I do this the scene will reload and it does work. BUT, I do not want to constantly reload my VR scene as it interrupts the flow.
I have tried setdisplay() - no luck. I am not sure which variable are being passed and if it is possible to do this. I have also trying loading the menu with "additive"...but no luck. I simply want to click on the world image and see the list of levels for that world.

How can I do this?

mahewitt
Site Admin
Posts: 273
Joined: Thu May 05, 2016 8:06 pm

Re: Worlds - Changing Level Menu in Scene

Post by mahewitt » Tue Aug 27, 2019 7:13 pm

So when you click the buttons. The following code is triggered in the WorldButton ClickUnlocked() method that sets the current levels as follows:

GameManager.Instance.Levels = GetGameItem<World>().Levels;

If you leave the ClickUnlockedSceneToLoad blank then no scene will be attempted loading so the question comes how to update the buttons. Note that you can subclass the WorldButton and use that in teh button prefab and override any methods as you see necessary.

So how to update the level buttons. Currently quite a bit of stuff here is done in the Awake() method which means the only option you might have is to use Instantiate() and pass in a prefab that contains the LevelButtons component. It will then create the buttons for the current world. You might need to subclass WorldButton, override ClickUnlocked() (calling base.ClickUnlocked() first) and put this code in there.

Not sure if that makes sense?

mahewitt
Site Admin
Posts: 273
Joined: Thu May 05, 2016 8:06 pm

Re: Worlds - Changing Level Menu in Scene

Post by mahewitt » Tue Aug 27, 2019 7:18 pm

.. As an alternative I can look at adding an event notificaiton to listen to e.g. World selection changes. Hopefully it won't be too big a job. Would still mean the old buttons get destroyed and new ones created though.

mahewitt
Site Admin
Posts: 273
Joined: Thu May 05, 2016 8:06 pm

Re: Worlds - Changing Level Menu in Scene

Post by mahewitt » Tue Aug 27, 2019 7:34 pm

I made a change as per the last post - I don't have a good test framework for this case yet so it isn't tested, but you could try replacing Scripts/GameStructure/GameItems/Components/AbstractClasses/CreateGameItemButtons.cs with the version from(take a backup first):

https://github.com/FlipWebApps/GameFram ... Buttons.cs

That adds an event listener for world selection changes that should recreate the buttons. Again untested and I shouldn't hardcode the WorldChangedMessage, but if you can see if this works that would be great.

tenfiddy
Posts: 24
Joined: Wed Jul 24, 2019 9:02 pm

Re: Worlds - Changing Level Menu in Scene

Post by tenfiddy » Wed Aug 28, 2019 12:41 am

It works !!! Hooray.

:D

I am posting a new question about star count per World. Thanks for the help.

tenfiddy
Posts: 24
Joined: Wed Jul 24, 2019 9:02 pm

Re: Worlds - Changing Level Menu in Scene

Post by tenfiddy » Wed Aug 28, 2019 1:42 am

But there is a small error...

NullReferenceException: Object reference not set to an instance of an object
GameFramework.GameStructure.GameItems.Components.AbstractClasses.CreateGameItemButtons`2[TGameItemButton,TGameItem].OnDestroy () (at Assets/FlipWebApps/GameFramework/Scripts/GameStructure/GameItems/Components/AbstractClasses/CreateGameItemButtons.cs:86)

mahewitt
Site Admin
Posts: 273
Joined: Thu May 05, 2016 8:06 pm

Re: Worlds - Changing Level Menu in Scene

Post by mahewitt » Sat Aug 31, 2019 5:26 pm

When does that error appear? It is OnDestroy, so I am assuming perhaps it is when you exit the game?

mahewitt
Site Admin
Posts: 273
Joined: Thu May 05, 2016 8:06 pm

Re: Worlds - Changing Level Menu in Scene

Post by mahewitt » Sat Sep 07, 2019 7:02 am

That null reference should be fixed. If you copy the following 2 files locally (take a backup first).

https://github.com/FlipWebApps/GameFram ... Buttons.cs

https://github.com/FlipWebApps/GameFram ... Buttons.cs

tenfiddy
Posts: 24
Joined: Wed Jul 24, 2019 9:02 pm

Re: Worlds - Changing Level Menu in Scene

Post by tenfiddy » Sat Sep 07, 2019 1:37 pm

Thanks - seems to work

Post Reply