Matthew-J-Green / dv-loco-analogue-control-mod

Derail Valley mod for analogue control in locomotives
MIT License
5 stars 2 forks source link

OnUpdate: NullReferenceException #8

Open rcambrj opened 2 years ago

rcambrj commented 2 years ago

I'm not sure when this broke (I haven't played in a while), but this is the error I'm getting in the log.

I notice that the nexus mods page is now hidden. This mod made Derail Valley. IMO not worth playing this game without this mod. So I hope you can find the time to fix this, or perhaps guide me a little bit so I can make a PR 🙌


System.NullReferenceException: Object reference not set to an instance of an object
  at LocoAnalogueControlMod.Main.OnUpdate (UnityModManagerNet.UnityModManager+ModEntry mod, System.Single delta) [0x00031] in <5377960b88224e1f8a839c8e5c59c708>:0 
  at (wrapper delegate-invoke) System.Action`2[UnityModManagerNet.UnityModManager+ModEntry,System.Single].invoke_void_T1_T2(UnityModManagerNet.UnityModManager/ModEntry,single)
  at UnityModManagerNet.UnityModManager+UI.Update () [0x00055] in <a3f360caaee746b3b5fa42474873be42>:0 ```
rcambrj commented 2 years ago

Is this the problem? I'm not super familiar with C#

Untitled

Matthew-J-Green commented 2 years ago

I haven't played this game in a while, nor looked at the code. A quick check does have that as the problem, you can comment out that part of the "OR" statement.

I did need to change the project to .net 4.7.2 for it to build for me. Thats under the "right click > properties > Application" under the project under the solution explorer

The log still seems to dump a bunch of errors in game but it does appear to work. Likely due to it not having loaded in the users inventory when checking if the mod should run its logic.

That piece of code I grabbed from a different mod, cant remember which one, but you might be able to find a other mods which have been updated to work with newer versions of the game and replace the code. Its likely that you would have to get the inventory from the player rather than from the "InventoryStartingItems" class directly. It used to be static, it now is not hence the error. or maybe check if the player is loaded in.

Theres no guarantees this still works with all loco types or with the remote controller or with multiple engines slaved, but the shunter did seem to work in the starting area. I believe there was an update a while back that implemented the functionality from the "MultipleUnits" mods so this may have broken more stuff.

It looks like you have the environment set up if you wanted to continue development on this. A few notes on how its set up.

rcambrj commented 2 years ago

It worked! Thanks for the advice :)

merlinfrombelgium commented 2 years ago

Hi @Matthew-J-Green and @rcambrj

Thanks to your comments on this page, I managed to get the mod working for me with the Saitek Throttle Quadrant and I'm so glad I did! So I committed my code for your review and to help others.