Mod loads in Unity but not in DFU 0.14.5

Discuss modding questions and implementation details.
Post Reply
User avatar
numidium3rd
Posts: 187
Joined: Sun Mar 25, 2018 12:34 am
Location: United States

Mod loads in Unity but not in DFU 0.14.5

Post by numidium3rd »

I have a mod called Hot Key HUD that's been working in DFU 0.14.5 for a while but now when I build a pre-compiled .dfmod while on the latest DFU master branch it fails with the following error message:
DFTFU 1.9.1: Failed to load mod data for `Hot Key HUD`. Exception: Object reference not set to an instance of an object
This error doesn't appear when I run the mod in Unity and everything works as expected. I can't debug exactly what is going wrong because the error only happens in release and the Player.log doesn't give a full stack trace. I do know that this message is printed from a try/catch block in the LoadGame method of SaveLoadManager when mod data is being de-serialized. Was there a recent change in the way mod data gets de-serialized on load?

For reference, here is the code my mod uses for NewSaveData, GetSaveData, and RestoreSaveData:
https://github.com/numidium/dfu-mods/bl ... HUD.cs#L84

User avatar
Magicono43
Posts: 1141
Joined: Tue Nov 06, 2018 7:06 am

Re: Mod loads in Unity but not in DFU 0.14.5

Post by Magicono43 »

numidium3rd wrote: Sat Mar 11, 2023 5:32 pm I have a mod called Hot Key HUD that's been working in DFU 0.14.5 for a while but now when I build a pre-compiled .dfmod while on the latest DFU master branch it fails with the following error message:
DFTFU 1.9.1: Failed to load mod data for `Hot Key HUD`. Exception: Object reference not set to an instance of an object
This error doesn't appear when I run the mod in Unity and everything works as expected. I can't debug exactly what is going wrong because the error only happens in release and the Player.log doesn't give a full stack trace. I do know that this message is printed from a try/catch block in the LoadGame method of SaveLoadManager when mod data is being de-serialized. Was there a recent change in the way mod data gets de-serialized on load?

For reference, here is the code my mod uses for NewSaveData, GetSaveData, and RestoreSaveData:
https://github.com/numidium/dfu-mods/bl ... HUD.cs#L84
I've recently added some save-data stuff to my WIP mod. Just keep in mind before reading further, the project is currently being worked on in DFU 0.14.4, mostly because 0.14.5 came a few months after the mod was first started, and just been too lazy to switch over until I'm ready to ship it out. Also I have not actually tried building the mod since I added the save-data stuff, so I've only been testing the "virtual" version, so my "advice" may not be that useful in your case, just disclaimer there.

Anyway, maybe you can try something like this? Basically switching the "mod.SaveDataInterface =" from instead of being under Init, have it under Awake() or Start(), atleast this is how it currently looks in my code, but have no idea if there is really any difference:

Code: Select all

public static LockedLootContainersMain Instance;
        public static LLCSaveData ModSaveData = new LLCSaveData();

        static Mod mod;

        // Global Variables
        public static GameObject ChestObjRef { get; set; }
        public static GameObject MainCamera { get; set; }
        public static int PlayerLayerMask { get; set; }
        public static AudioClip LastSoundPlayed { get { return lastSoundPlayed; } set { lastSoundPlayed = value; } }
        public static PlayerEntity Player { get { return GameManager.Instance.PlayerEntity; } }
        public static PlayerActivateModes CurrentMode { get { return GameManager.Instance.PlayerActivate.CurrentMode; } }
        public static WeaponManager WepManager { get { return GameManager.Instance.WeaponManager; } }

        bool isBashReady = true;

        // Mod Textures
        public Texture2D ChestChoiceMenuTexture;
        public Texture2D InspectionInfoGUITexture;

        [Invoke(StateManager.StateTypes.Start, 0)]
        public static void Init(InitParams initParams)
        {
            mod = initParams.Mod;
            var go = new GameObject(mod.Title);
            go.AddComponent<LockedLootContainersMain>(); // Add script to the scene.

            go.AddComponent<LLCObject>();

            mod.IsReady = true;
        }

        private void Start()
        {
            Debug.Log("Begin mod init: Locked Loot Containers");

            Instance = this;

            mod.SaveDataInterface = ModSaveData;

            MainCamera = GameObject.FindGameObjectWithTag("MainCamera");
            PlayerLayerMask = ~(1 << LayerMask.NameToLayer("Player"));

            PlayerActivate.RegisterCustomActivation(mod, 4733, 0, ChestActivation);

            PlayerEnterExit.OnTransitionDungeonInterior += AddChests_OnTransitionDungeonInterior;

            // Load Resources
            LoadTextures();
            LoadAudio();

            RegisterLLCCommands(); // For testing custom windows

            Debug.Log("Finished mod init: Locked Loot Containers");
        }
Here is what the start of the "LLCSaveData" class looks like as well:

Code: Select all

[FullSerializer.fsObject("v1")]
    public class LLCSaveData : IHasModSaveData
    {
        public Dictionary<ulong, ClosedChestData> ClosedChests;
        public Dictionary<ulong, OpenChestData> OpenChests;

        public Type SaveDataType
        {
            get { return typeof(LLCSaveData); }
        }
        ...
Not sure if that will help at all, just figured I'd give it a shot.

User avatar
numidium3rd
Posts: 187
Joined: Sun Mar 25, 2018 12:34 am
Location: United States

Re: Mod loads in Unity but not in DFU 0.14.5

Post by numidium3rd »

I moved Mod.SaveDataInterface = Instance to Awake() and now I'm getting a new error.
Spoiler!

Code: Select all

ArgumentException: Value does not fall within the expected range.
  at HotKeyHUD.HotKeyHUD.Awake () [0x00019] in <26c7f65e958047bba8d95d176bcbff4c>:0 
UnityEngine.GameObject:Internal_AddComponentWithType(Type)
UnityEngine.GameObject:AddComponent(Type)
UnityEngine.GameObject:AddComponent()
HotKeyHUD.HotKeyHUD:Init(InitParams)
System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)
System.Reflection.MethodBase:Invoke(Object, Object[])
DaggerfallWorkshop.Game.Utility.ModSupport.ModManager:InvokeModLoaders(StateTypes)
DaggerfallWorkshop.Game.Utility.ModSupport.ModManager:StateManager_OnStateChange(StateTypes)
DaggerfallWorkshop.Game.StateManager:TriggerStateChange(StateTypes)
DaggerfallWorkshop.Game.StateManager:ChangeState(StateTypes)
DaggerfallWorkshop.Game.StateManager:.ctor(StateTypes)
DaggerfallWorkshop.Game.GameManager:get_StateManager()
DaggerfallWorkshop.Game.Automap:Update()
It doesn't seem to want to accept the HotKeyHUD as an implementation of the IHasModSaveData interface. If I can't use it as such then that would be sad because then I'd have to make the code more complicated in order to work. It was working just fine before :( .

EDIT: okay, so that error was happening because I put LoadSettingsCallback in Awake() as well. Ignore all that. It's still not working but what I'm seeing now is this repeated over and over in Player.log:
MissingMethodException: UnityEngine.KeyCode DaggerfallWorkshop.Game.InputManager.GetAnyKeyDown(bool)
Progress! Maybe there was a change in the InputManager since 0.14.5.

User avatar
Magicono43
Posts: 1141
Joined: Tue Nov 06, 2018 7:06 am

Re: Mod loads in Unity but not in DFU 0.14.5

Post by Magicono43 »

Not that I know if this is related at all to that specific error. But maybe you could try instead of using the monobehavior "Awake()" instead use "Start()". I don't exactly remember when I had something happen, but I noticed when using Awake I would sometimes get errors for whatever reason, and when I started using Start instead they went away if my memory is correct. So I made a point to myself to basically always use Start in the main mod monobehavior file.

But as I said, just a stab in the dark there, no clue if it has anything to do with that error.

User avatar
Magicono43
Posts: 1141
Joined: Tue Nov 06, 2018 7:06 am

Re: Mod loads in Unity but not in DFU 0.14.5

Post by Magicono43 »

numidium3rd wrote: Wed Mar 15, 2023 7:01 pm Progress! Maybe there was a change in the InputManager since 0.14.5.
That is also entirely possible, I've unfortunately not worked with keyboard input stuff at all to know if anything was changed recently :P

User avatar
numidium3rd
Posts: 187
Joined: Sun Mar 25, 2018 12:34 am
Location: United States

Re: Mod loads in Unity but not in DFU 0.14.5

Post by numidium3rd »

Yep, that is in fact the issue. The method signature for GetAnyKeyDown() was changed to have one boolean argument instead of no arguments back in November so I would just need to roll back the master to a point before then and build the dfmod to get it to work with 0.14.5.
https://github.com/Interkarma/daggerfal ... f865fR1122

PSA to anyone using that method in your mod: you'll need to release a new version once the next DFU build comes out.

User avatar
Magicono43
Posts: 1141
Joined: Tue Nov 06, 2018 7:06 am

Re: Mod loads in Unity but not in DFU 0.14.5

Post by Magicono43 »

Good to hear you found the problem for your case atleast.

Post Reply