Forum rules - please read before posting.

Nintendo Switch crash at startup

edited August 2021 in Technical Q&A

I know Switch isn't officially supported by AC, but roaming around the forum I've seen plenty of people actually managing to make it work.
I've actually followed some of the advices I found on this forum, but the application keep crashing as soon as the "Made with Unity" screen comes up. The log reports it's a CreateDirectory() Error: nn::fs::ResultUnsupportedOperation: Error: Unsupported operation.

I know that the default save system using the persistentDataPath is not compatible with consoles, but I've already gone ahead and added a component onto the PersistentEngine prefab that does the following:

SaveSystem.SaveFileHandler = new SaveFileHandler_PlayerPrefs();

It doesn't seem to sort any effect though and I keep getting this error, even explicitly doing the same thing for Options as well, even if it's not required.

Here's the log trace segment where it happens:

...
[LocalFileSystemSwitch::CreateAsDir] Trying to write to 'rom:' mount path 'rom:/Data/%HOMEPATH%'! 
****** FS ERROR INFORMATION ******
Error: Error occurred at CreateDirectory().
nn::fs::ResultUnsupportedOperation: Error: Unsupported operation.
More infomation may be provided by enabling 'FS Access Log Mode' at 'DevMenu: Debug'.
...

To be clear, there is no custom code using the persistentDataPath at the start of the game. Just AC.

Comments

  • Are saves being stored correctly in PlayerPrefs when testing in the Editor?

    What's the exact code in full that you're using?

  • Yes, in editor all save data are correctly saved in PlayerPrefs.
    The Component I put on the Persistent Engine is the following:

    public class SaveSystemHandler : MonoBehavior
    {
        private void Awake() 
        {
            SaveSystem.SaveFileHandler = new SaveFileHandler_PlayerPrefs();
            Options.OptionsFileHandler = new OptionsFileHandler_PlayerPrefs();
        }
    }
    
  • Try preceding the script with an enforcement of its execution order:

    [DefaultExecutionOrder (-100)]
    

    If that fails, try also placing the script in your first scene.

    Even if AC uses the default SaveFileHandler, though, it doesn't directly attempt to create any directory on the filesystem.

  • FS_ACCESS: { start:  92119037, end:  92119037, result: 0x00000202, handle: 0x0000000000000000, priority: Normal, function: "GetEntryType", path: "rom:/Data/%HOMEPATH%", entry_type: Directory }
    [LocalFileSystemSwitch::CreateAsDir] Trying to write to 'rom:' mount path 'rom:/Data/%HOMEPATH%'! 
    FS_ACCESS: { start:  92119037, end:  92119037, result: 0x0031B802, handle: 0x0000000000000000, priority: Normal, function: "CreateDirectory", path: "rom:/Data/%HOMEPATH%" }
    ****** FS ERROR INFORMATION ******
    Error: Error occurred at CreateDirectory().
    nn::fs::ResultUnsupportedOperation: Error: Unsupported operation.
    ------------
    AbortObserver called: Failed: nnFsResult
      Module: 2
      Description: 6364
      InnerValue: 0x0031b802
    Condition: nn::Result::IsSuccess()
    Function: CreateDirectory in D:\Home\teamcity\work\sdk\Programs\Chris\Sources\Libraries\fs\fsa\fs_UserFileSystem.cpp:58
    

    This is the log coming from switch. I'm not entirely sure it's AC causing this, but given the directory of fs_UserFileSystem.cpp, I figured maybe it had to do with AC on some degree. I've tried enforcing the execution order, I tried moving the script in the initial scene (which is not an AC scene) and I tried doing both at the same time. No success.

  • edited August 2021

    The file handler may be a red-herring, in that case. The easiest way to determine this would be to modify AC's SaveSystem script to enforce saving to PlayerPrefs directly, without the need for a separate script.

    At the top of SaveSystem.cs, replace:

    #if UNITY_WEBPLAYER || UNITY_WINRT || UNITY_WII || UNITY_PS4 || UNITY_WSA || UNITY_WEBGL
    #define SAVE_IN_PLAYERPREFS
    #endif
    

    with:

    #define SAVE_IN_PLAYERPREFS
    

    If you still get the issue, it's likely not related to the file handler.

    Does the error appear when loading the first AC scene, or the game's initial scene?

  • I still get the error. It happens at the very startup of the game, when the "Made with Unity" screen comes up, which I'm not sure happens before my first scene is loaded or if both are loaded at the same time. Point is, it happens as soon as the game loads up. I've looked around and on these forums I found someone having the same issue, but it seems they solved it with just overriding the file handler from an external script (this topic).
    I've also tried to build an empty project to see if it would crash as well, but it starts no problems. I've added AC and it started crashing again.

  • UPDATE: I forgot to remove the piece of code overriding the file handler and it seems to be working just fine now! I'll test it a bit more, but it seems we found the point it was breaking at.
    Thanks for the help!

  • edited August 2021

    Sad Update: It seems I was wrong. The game started because I prevented the game from loading the first AC scene. Here's the code in the initial scene:

    public class Initializer : MonoBehaviour
    {
        [SerializeField]
        private bool _loadScene;
        [SerializeField, Scene, ShowIf("_loadScene")]
        private string _sceneName;
    
        private void Awake() 
        {
            AC.KickStarter.settingsManager.inputMethod = AC.InputMethod.KeyboardOrController;
            if (_loadScene) 
            {
                UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(_sceneName);
            }
        }
    }
    

    if _loadScene is false, the application doesn't crash. If it's true, it does. _sceneName refers to the very first AC scene in the game.

  • Hopefully-Helpful-Update: Disabling the SaveSystem component on the PersistentEngine everything works just fine.

  • edited August 2021

    I found the issue. I don't understand why no one else seems to have had this problem, but apparently the line responsible for the crash was actually inside the OnEnable() method in SaveSystem.cs:

    if (string.IsNullOrEmpty (persistentDataPath))
    {
        persistentDataPath = Application.persistentDataPath; // THIS LINE
    }
    EventManager.OnAddSubScene += OnAddSubScene;
    

    I'm not sure how that property is calculated, but it seems to be trying to create a directory in a place the Switch doesn't allow to write. Commenting that line fixes the crash and allows the application to smoothly transition from the initial scene to the first AC scene.

  • Excellent, thanks for the update.

    That change won't affect your game if you continue to use PlayerPrefs, but will cause problems if you switch back to SystemFile when building to another platform.

    I will provide an official fix that works for both in the next update.

  • We had this exact same issue and figured out that disabling SaveSystem in the PersistentEngine fixed it, but well done for figuring out the line that was actually causing it.

    Now, if only there was an easy way for us to have the Switch STORE saved games after closing and re-opening your app. If you happen to know of any way to get the save features working on Switch then please let me know :)

  • The workings of the Switch's save system will be protected behind developer NDAs. You should find the details with Nintendo necessary to create a custom save file handler.

    I would recommend starting out with the PlayerPrefs save handler, though.

  • I managed to fix it last night. All I'll say to anyone still having this problem is to check to Nintendo Dev Forums. Someone's created a plugin to force Switch to save and store PlayerPref saves.

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.