Jump to content

How to know when settings are accepted?


Recommended Posts

I'm using the new class for settings:

GameParameters.CustomParameterNode

However, I need to call a function when the Accept button is pressed.  How can I do that?

Thanks in advance

8 minutes ago, linuxgurugamer said:

I'm using the new class for settings:

GameParameters.CustomParameterNode

However, I need to call a function when the Accept button is pressed.  How can I do that?

Thanks in advance

I think this is the way, please confirm:

 void Start()
        {
            GameEvents.OnGameSettingsApplied.Add(ReloadSettings);
        }

 

Link to comment
Share on other sites

Not at a computer, so I apologise for the lack of specifics.

If I remember correctly, that particular event is for the game settings, so it won't get fired when starting a new game, but it will when changing difficulty settings in-game.

Really depends what you're trying to accomplish, but there may be better options:

- OnSave/OnLoad logic in your parameter class.

- if what you're trying to do is tied to a specific field, make it a property and add the logic in the set method.

- do "first time" instantiation logic in a scenario module instead

Link to comment
Share on other sites

23 hours ago, nightingale said:

If I remember correctly, that particular event is for the game settings, so it won't get fired when starting a new game, but it will when changing difficulty settings in-game.

I appreciate the reply.  I actually need to know when settings are changed in-game, so this will do it

Link to comment
Share on other sites

  • 3 months later...
On 11/10/2016 at 1:42 AM, nightingale said:

... If I remember correctly, that particular event is for the game settings, so it won't get fired when starting a new game, but it will when changing difficulty settings in-game.

It is possible to accept in-game changes to custom difficulty settings, and not have OnGameSettingsApplied fired. @Gotmachine already reported it here issue 13591. It can, IMO, be a major gotcha.

How do you solve this catch? Do you build in a mechanism in your custom parameters to 'broadcast' when the settings are changed? Do you ignore that particular case (the 'close' button option)? Or something third?

Edited by Rodhern
spelling
Link to comment
Share on other sites

In my case, I ignored the problem and reloaded my settings in the onLevelWasLoaded event (was actually better since settings changes while in-flight caused issues in my specific case).

This said, I think the best and most reliable way to track every time the settings menu is closed is to do it in the OnSave function of your CustomParameterNode.

Link to comment
Share on other sites

17 hours ago, Gotmachine said:

In my case, I ignored the problem and reloaded my settings in the onLevelWasLoaded event (was actually better since settings changes while in-flight caused issues in my specific case).

This said, I think the best and most reliable way to track every time the settings menu is closed is to do it in the OnSave function of your CustomParameterNode.

Ahh, thanks. I hadn't even considered using the OnSave of the CustomParameterNode. Sounds like a good idea.

Link to comment
Share on other sites

23 hours ago, Gotmachine said:

This said, I think the best and most reliable way to track every time the settings menu is closed is to do it in the OnSave function of your CustomParameterNode.

Hmm. I just tried overriding the OnSave method. It seems to me, if for instance I am in the Space Center scene and change the custom settings, OnSave is not called when I click 'Apply'. Does it work for you?

Link to comment
Share on other sites

Just checked : OnSave (and OnLoad) is called every time the menu is opened, but also on all scene changes. So you're right, that won't work for our purpose...

But maybe there is another workaround : set a boolean to true in the overrided "Enabled" function (it control UI options visibility, so should be called every time the menu is opened). Then check for this boolean in the onGameUnpause event, do your thing and reset it to false. There is a catch : if the player open the menu on a new game (in the main menu), the boolean will be set to true and your code called the first time the player do a pause/unpause. Depending of what you what to do, this could be a problem. Maybe there is some event or a way to reset the boolean when a game is first created, but I didn't found how...

Link to comment
Share on other sites

49 minutes ago, Gotmachine said:

... in the onGameUnpause event ...

Splendid idea! The problem with OnGameSettingsApplied was that it wasn't always triggered, but if onGameUnpause is (and it sounds plausible that it is) then that is a very good work-around. In my particular case I don't think it is important to know if the difficulty settings panel was actually opened, so even if it fires onGameUnpause a bit often that is fine by me.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...