Forum rules - please read before posting.

KickStarter not initialized ? (iOptionsFileHandler implementation)

Hi !
AC 1.71.4

I'm running into a problem when trying to use my custom implementation of the iOptionsFileHandler interface.
I put a line to replace the regular system in a custom script and i attached that to the persistentEngine prefab.

It calls the methods it should, however, it throws a NullReferenceException in AC.Options.LoadPrefs()
After adding logs, it is clear to me that the culprit is KickStarter itself.
Maybe it's not initialized yet, i'm not sure. But as soon as the code tries to access any of its properties like saveSystem or playerMenus, in the Options.cs file, i get that error.

I tried several things and, when i replace the options system in the start function of another script instead of awake(custom script attached to persistent engine), the error disappears but the options system behaves in the wrong way (which i assume is normal since it doesn't load the options from the file i save them to at the start).

Any idea what might cause this ?
I had no issue with replacing the saveSystem so i'm not sure why it's behaving like this for the options...

Comments

  • KickStarter properties are automatically set when called for the first time. Once the PersistentEngine has been spawned, they should then be findable.

    Can you share the exact NRE error you're getting, stacktrace included? What other messages are appearing before/after it in the Console?

  • Switched it back to my initial method (which is a class called when the game starts and in the awake method).

    Here's what i get:

    NullReferenceException: Object reference not set to an instance of an object.

    at AC.Options.LoadPrefs () [0x00000] in <00000000000000000000000000000000>:0
    at Clemenc.OnStartGame.Awake () [0x00000] in <00000000000000000000000000000000>:0

    And before that, it shows the debug i added right after there:

            optionsData = LoadPrefsFromID (GetActiveProfileID (), Application.isPlaying, true);
    
            if (optionsData == null)
            {
                Debug.Log("No Options Data!!");
                ACDebug.LogWarning ("No Options Data found!");
            }
            else
            {
                Debug.Log("LoadPrefs() => else (optionsData not null => "+optionsData+") -- App.playing?"+Application.isPlaying);
                Debug.Log("Languages count = "+KickStarter.runtimeLanguages.Languages.Count);`
    

    LoadPrefs() => else (optionsData not null => AC.OptionsData) -- App.playing?True

    So it enters the else, shows the first Debug.Log entry and then i get the null reference exception.
    Just to be sure, i commented that and the subsequent calls to KickStarter. "anything".
    It then showed debug right before the last 2 calls.
    I commented one, still got the error.
    I commented both, no more errors.
    Of course, this means the saves aren't loaded and all kinds of problems since the options don't load correctly with commented stuff but made me pretty sure the problem is that it's trying to access something that's null.

  • And here's the content of the string i get from the file where i save the options data...
    XML<?xml version="1.0" encoding="utf-8"?><OptionsData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><language>1</language><voiceLanguage>0</voiceLanguage><showSubtitles>false</showSubtitles><sfxVolume>0.07812493</sfxVolume><musicVolume>0.967881858</musicVolume><speechVolume>1</speechVolume><linkedVariables /><saveFileNames>0:AutoSave|1:Save 1|2:Save 2|3:Save 3|4:Save 4|5:Save 5|6:Save 6|7:Save 7|8:Save 8|9:Save 9 |10:Save 10|11:Save 11</saveFileNames><lastSaveID>0</lastSaveID><label>Profile 1</label><ID>0</ID></OptionsData>

  • The code you're sharing isn't dealing with the custom iOptionsFileHandler directly. Are these not two separate issues?

    AC will load Options Data by itself automatically at the correct time - you don't need to call LoadPrefs manually.

    Assigning an iOptionsFileHandler is a separate operation - are you saying that things work if you don't specifically do this? What is the exact code you're running, if so?

  • edited April 2021

    What happens is AC starts the LoadPrefs() method from the AC.Options class when i replace the options handler.

    (it's in "set" of the iOptionsFileHandler).
    set { optionsFileHandlerOverride = value; LoadPrefs (); }
    So i replace the options handler, then AC calls LoadPrefs and the error happens.

    Things work if i replace the options handler later on but obviously it doesn't load the options i saved in files at game start (which is an issue because the language is in the options and it should change the main menu).

  • Sorry - I'm with you now.

    Is this only occuring in Builds, or the Editor as well?

    The KickStarter's SetPersistentEngine function needs to have been completed before its various properties can be read, since it's at the end of this function that the persistentEnginePrefab variable is assigned.

    Try placing a Debug.Log in there to see if it's being called after your iOptionsFileHandler assignment.

    Rather than using the Awake function to do so, try hooking into the OnInitialiseScene custom event, which will be triggered once the PersistentEngine has been added, but before saved data is loaded.

  • Update:
    The error is gone Oo
    I'm not sure what happened but what i did was remove the component on the persistentEngine, test different things, and then at some point i went back to that way of doing it.
    So i guess it must have been something that wasn't done correctly in the first place or maybe some code, somewhere.

    Anyway, sorry for your time, it now works as intended.

  • No problem, thanks for the update.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.