Hello,
when unity 5.4 came out it changed how loading serialized assets works. Now you have to initialize everything in start, awake, or update. This broke one of my functions, and unfortunately I don’t have enough coding experience to fix it(artist.)
public static T Load<T>(string resourcesPath)
where T : Object {
return Resources.Load(resourcesPath, typeof(T)) as T;
}
The error I get is "load is not allowed to be called during serialization, call it from awake or start instead ".
Since this isn’t being initialized on start it’s not utilizing the function properly. How can I put this in start/awake to make this run normally? I’m not even sure if you can call generic types.
Thank you.
My guess is you are calling this method from a field initializer. Something like private GameObject m_SomeAsset = Load<GameObject>("SomeAsset.prefab"); This should never be necessary. You should always do something like this:
[SerializeField]
private GameObject m_SomeAsset;
And then just link the asset directly in the inspector and the reference will be serialized. You may find this page helpful.