0
Answered

Initialise AotList value using float array in ScriptableObject

KubaBaku 3 years ago updated 3 years ago 3

I made a custom ScriptableObject class to store some values of character (HP,MP,etc.),

but after I initialised the AotList value in the GameObject,

the value of them changes at same time, and they even affects the value of the SO used to initialise! (The changed values are saved into the SO)

I asked at Discord and someone told me try not to use the method above to initialise, then i tried to write a method like this:

public void Initialise(GameObject go, string characterID)
{
float[] status = Resources.Load("Characters/" + characterID).status;
float[] statusMax = Resources.Load("Characters/" + characterID).status;

Variables.Object(go).Set("status", status);
Variables.Object(go).Set("statusMax", statusMax);
}

...but the problem still occures :( Anyone have idea what's going on?

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
GOOD, I'M SATISFIED
Satisfaction mark by KubaBaku 3 years ago
+1

nothing to do with floats, someone just asked this. Check my be answer for why. It's legit behavior. https://support.ludiq.io/communities/5/topics/2355-variable-value-is-changing-when-i-using-get-variable

+1
Answered

Hi KubaBaku!

As pointed out, I think this is just normal Unity behaviour with ScriptabeObjects you're seeing.

You're not copying the list (the float array) when using Set units, you're referencing the same list, the one that is stored on your scriptable object asset itself. That's why it's saved and shared.

The fact that you predeclared your variables as AotList has no impact here, because you're overwriting them entirely with the Set.

I can't think of a quick workaround right away without using a Create List + a For Each loop to populate it with new values. 

Oh! Thanks for the explanation and solution from JasonJonesLASM and Lazlo Boni!