What's the best way to serialize an array of references to C2 object instances?
I have a third-party behavior, that holds an array of references to C2 object instances. (These references are gotten from the SOL.)
This array is part of the behavior's internal state, with "this.references" being declared in the onCreate() function.
To get this behavior to cooperate with C2's native Save/Load state feature, I need to be able to save and load the behavior's internal state, using the saveToJSON() and loadFromJSON() functions.
The saveToJSON() returns an object to be serialized via JSON.stringify(), I think.
I think that JSON.stringify(), if given an array of C2 object refs, will try to serialize the entirety of each C2 object referenced. This causes a "Circular structure error", and isn't what I need to do anyway.
I don't want to serialize C2 objects, as all I need to save are the references to those objects.
Maybe I can get the UIDs of the referenced objects, and save those.
Then I can rebuild the correct references upon loading by looking up object instances by the saved UIDs.
Does anyone have advice on serializing an array of C2 object instances?
Any thoughts or sugestions are welcome.
Finally, the specific behavior I'm trying to extend is Azis's "Store Reference" behavior:
I've already found and fixed some other problems with this behavior, but I just recently noticed it has no Save/Load support built in.
It's a nice idea for a behavior, but I'm just about at the point of replacing it with native UID-based events, since I know I won't have to fix anything else in the future if I just stick to event sheets.