(Solved, but unhappy)ScriptableObject.Awake never execute

So. I got an answer from Unity about the report.

I have to test it and IMHO, Devs: Take a kind look at this!

The first Test I made

The scripts are simple:

using UnityEngine;

namespace Game.Test {
   public class Test : MonoBehaviour {
      public TestSO testing;
   }
}
using UnityEngine;

namespace Game.Test {
   public class TestSO : ScriptableObject {
      protected virtual void Awake() { }
   }
}
using UnityEngine;

namespace Game.Test {
   [CreateAssetMenu (menuName = "Test/Testing ScriptableObject")]
   public class TestChildSO : TestSO {
      protected override void Awake () {
         base.Awake ();
         Debug.Log("Testing");
      }
   }
}

Observation: I created the ScriptableObject file on an folder and attached to the slot on the gameObject in inspector.
I thought it required the Awake function on the base class, but when I run, it doesn’t work! So…

The Second Test I made

Since the first test didn’t work I add some code to the Test class:

private void Awake() {
   testing = (TestSO) ScriptableObject.CreateInstance(typeof(TestChildSO));
}

And it work!

Conclusion: In my point of view, this method should be renamed to OnCreated. Why is that: Simple, the Awake does not run if a GameObject is on the scene, but only if a script creates the ScriptableObject!

When a Object is Awakening, ( if the ScriptableObject have the same method and the documentation says that it works similar way as MonoBehaviour, ) then the ScriptableObjects must execute Awake too! Otherwise it’s purpose lacks meaning! It is an OnCreated execution! More logic and coherence. Remember: this is my point of view and my argument!

43 Likes