Forum rules - please read before posting.

Issue with multiple remember scripts

I have some custom systems that I've integrated with the standard AC load/save mechanism (following the tutorial for creating custom Remember scripts). These scripts are working individually without any issue. However, I'm having the following problem:

When I have more than 1 remember script on a given object (in this case a hotspot) I am getting null reference exceptions when trying to load a saved game and some of my data is not getting resolved. For instance the Remember Hotspot and any of my custom Remember scripts. If I use just a single script I don't have this issue.

I'm not having an issue using two of your remember scripts (for instance, Remember Hotspot and Remember Collider) though.

Here is one of my scripts that is working by itself but throws a null reference at line 28 when any other Remember script is instantiated on the same object:

image

I'd appreciate any thoughts you have... again, working exactly as intended when it's by itself.

Comments

  • Post the NRE error in full - we'll need to know what it's referring to.
  • Here it is:

    image
  • I think it's because you're assuming that WireObject.AllReactions has the same array size as the loaded data, and iterating through WireObject instead of wireData.  I don't know the class structure of WireReactions, but it may be a fault in your code rather than with AC.  You can see what data AC is loading with the following in line 25/26:

    Debug.Log ("String loaded: " + stringData);
    if (wireData != null) Debug.Log ("Found " + wireData.AllReactions.Count + " Reactions");


  • edited November 2016
    I did try that... though the number of elements should always be identical in this case. So I put together a test class and remember script to try and isolate this (even if it's still my fault). This removes any array count issue from the equation and simply saves a class with a single integer and single string variable.

    Here is the simple set of test scripts. Just need to add to a hotspot.

    Behavior is identical to what I reported above:

    When on a hotspot it initially works 100% of the time without errors. As SOON as I add the "Remember Hotspot" script I get the error posted above. Using the latest AC plus Unity 5.5 Beta 11 and Unity 5.4 latest stable release.

    Thanks for your help.
  • Also, I did run your suggested debug and found the following:

    1. When my script is present on a hotspot (without any other remember scripts) things work and the log spits out a 1368 character string followed by the expected number of reactions.

    2. When I add the "Remember Hotspot" script ONLY the first part of the string is debugged: 344 characters. In addition, the next debug log line doesn't run - presumably because wireData is reporting as null.
  • I'll take a look at the test scripts and get back to you.
  • edited November 2016
    This is because your script does not check to see if the loaded data is indeed TestData.  Since all Remember scripts on a GameObject share the same ID, the LoadData function is called on all of them and a final check must then be made to check that the data type is correct.  You can see this check made in the other Remember scripts.

    To fix, just insert this after the LoadScriptData call:
    if (testData == null) return;

    I'll update the save-data tutorial to include this requirement.
  • Fixed! Thank you, Chris. 

    Makes perfect sense (hindsight being 20/20).
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.