Hello,
i am kind of lost on this one and spent now around 10h tying to get this into my head. However at this point i assume it is unintended behavior. v 2019.4.34f1
So i do have scriptable objects
public abstract class ModifierType : ScriptableObject
{
[SerializeField] string soid;
#if UNITY_EDITOR
protected virtual void OnValidate()
{
string path = AssetDatabase.GetAssetPath(this);
soid = AssetDatabase.AssetPathToGUID(path);
}
#endif
}
So they get their guid in the editor. These scriptable objects are a field of another class
[Serializable]
public class Stat
{
public ModifierType type;
[SerializeField] string _typeSOID;
public string TypeSOID
{
get { return _typeSOID; }
set
{
_typeSOID = value;
}
//other fields
}
}
This class is the field of another scriptable object
public class Item : ScriptableObject
{
public List<Stat> stats;
#if UNITY_EDITOR
void OnValidate()
{
string path = AssetDatabase.GetAssetPath(this);
soid = AssetDatabase.AssetPathToGUID(path);
foreach (var i in stats)
{
i.TypeSOID = i.type.soid;
}
}
#endif
}
So i do have a field in a scriptable object that depends on another field of another scriptable object. (this is because items get instantiated and i need this information for serialization)
This works totally fine as long as i am in the editor. However, when i built, random “Stat” objects pass an empty string (“”) as their soid to the item.
Some random observations of mine:
-
the stats are not totally random. from the 200 available it is always a random number of the same 10 (the first 1-4 of an item and the last, for what it is worth)
-
a debug message in the item class gives way more messages then deleted strings or stats. this means OnValidate gets called way more then id expect when building
-
the number of null soids is different from build to build
-
if all stats are referenced by either a prefab or other scriptable object everything is fine
-
it happens only for the ModifierType class. if i remove the OnValidate code from Item the soids persist correctly
-
it only happens to the string field of “stats”. other fields are remembered correctly. this makes me assume, that it is indeed the “ModifierType” object that loose value during the building process. however if i check them after the build, they all have their ID, they are just not correctly passed to the item
At some point i assumed that it had something to do with script execution order. But the order can only be set for monobehaviours, if i read the documentation correctly. Even then, their should be no point in which a string field of ModifierType should be null. They have to be reset during the built or something. Other than that i am aware that string is a reference type, but at no point is a soid set to “”, so this should also not be the cause.
Id like to avoid the adressables package if possible. I made sure, that the soid of ModifierType is not set by another class (it is actually only acessible through a property, which is not shown). And just to be sure: i am not trying to change values at runtime, the information is lost when i built.
So thanks for reading, i am glad for every hint