- Home /
Awake() is not called automatically by Unity on targets reference
I have two classes one is an editor (extends Editor) and other is a MonoBehaviour one (the target class).
On "OnInspectorGUI()" method I get access to the MonoBehaviour class through the target:
public override void OnInspectorGUI()
{
var script = (PackScript) target;
script.Awake();
}
However I've noticed when I'm accessing PackScript class, the Awake() is not called by Unity and I need it to accomplish some routines, then I decided to call it manually and I'm not sure if this is a good idea or it breaks some design pattern, I don't know.
Is it supposed to act like this in the case of Unity doesn't call Awake from a target object?
Awake is called at runtime on classes derived from $$anonymous$$onoBehaviour. You may need to use ExecuteInEdit$$anonymous$$ode to get the behavior you expect in the editor
brianruggieri,
Thanks so much, this solution works nicely here.
Answer by Noztradamuz · Sep 05, 2014 at 06:41 PM
As far as I know you cannot call Awake() manually, Awake it's a reserved function and it`s called automatically on the awake of the script, perhaps you want to create some Init() method or something like that to manually initialize the script.
You can call Awake manually, its just a function. But you shouldn't.
Your answer
Follow this Question
Related Questions
Draw specific Object Inspector into Rect 1 Answer
Way to graphically visualize a Vector2 or Vector3 in inspector? 2 Answers
Changes in Inspector have no effect 0 Answers
How to set a shared material in inspector? 0 Answers
How do I get the default scene GUI for a CustomEditor for RectTransform? 1 Answer