Forum rules - please read before posting.

Can't get a custom Remember Script to work

Hi Chris,
I need to create a custom Remember script for a Diary that I created.
The main thing to "save" is the diary pages, which are ultimately a Sprite array in my Diary component.
I followed the instructions from your tutorials which did make quite a lot of sense.

I attached the script to my Diary Game Object which also has my Diary component (with the sprite array).

When the Sprite array in my Diary game object is back to square one. Also, I placed some console Debugs on the beginning and end of my SaveData function but it doesn't seem they are being called at all. Same for the LoadData function.

Any idea what I might be doing wrong? I wanted to past the code here but it doesn't seem I can do code formatting.

Thanks,

Duarte




Comments

  • Where is this diary in your hierarchy?  Is it instantiated at runtime, or present in the scene file?

    You will certainly have to share the code - you can use http://pasteall.org/ to post formatted code.
  • Hi Chris,
    Thanks for your reply.
    The Diary is a Menu that is set to "Enable on start", so I have a prefab with a canvas linked in my menu item.
    Then inside that prefab I have a child object that is my custom Diary (with the sprite array).
    Here is the code for the Remember script:
    Thanks again for your help!
    Cheers,
  • The second Debug statement won't call in your SaveData function because it is beneath the return statement.

    However, I would say this is due to your diary not being a scene item.  It is instead placed outside of any specific scene, which depending on your Unity version will be explicitly shown as "DontDestroyOnLoad" in your Hierarchy.

    The correct way to save such data, is to save it as global data - see this tutorial.  AC's own menu data is similarly stored in global memory - nothing scene-related.

    You also cannot save non-standard types - so an array of Sprites is not going to serialize (this is now a Unity issue, not AC).  You're restricted to standard C# types such as int, string, float, bool.  AC gets around this by saving the names of asset files as strings, and loading them in from Resources folders.

    When arrays are concerned, AC stores all data into one string and separates items by a special character, such as a pipe (|) character.

    For an example of AC saving arrays of non-standard types, see the RememberFootstepSounds component in the latest release.
  • Hi Chris,
    Thanks for your quick reply.
    No comments on the debug statement after return (writing code too late in the night :P)
    I think I get the gist of it so I will try to workaround the issue of arrays. I assume when you say "AC stores all data into one string and separates items by a special character, such as a pipe (|) character." that the concatenation and parsing are all done by AC and there would be no function already available for this (so I will need to code something similar).
    I will look into the global data tutorial as well as the RememberFootSteps example.
    Thank you so much for the help Chris, your support is stellar as always.
    Cheers,
  • Hi Chris,
    Just to let you know this worked fine.
    Used a global variable to store all my texture names concatenated with a pipe and then on PreLoad I parse it and build my sprite array.
    Thank you so much!
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.