- Home /
Awake not called if class has static member
Hey,
my code:
public class EntryPoint : MonoBehaviour
{
public NetworkManager networkManager { get; private set; }
public GameLogic gameLogic { get; private set; }
public InputHandler inputHander { get; private set; }
public RenderManager renderManager { get; private set; }
void Awake()
{
networkManager = new NetworkManager("127.0.0.1", this);
gameLogic = new GameLogic(this);
inputHander = new InputHandler(this);
renderManager = new RenderManager(this);
Debug.Log("asd");
}
As soon as I make eg the reference to inputHandler static,
public static InputHandler inputHander { get; private set; }
Awake() will not be called anymore. How can I fix this?
I don't see anything wrong with this. Do you see a debug statement at the beginning of the Awake method? It's possible you're running into a script error which prevents reaching the end of the method.
Answer by Gor1lla · Jul 03, 2017 at 03:45 PM
The mistake was that the usage of OnValidate() resulted in a method trying to access a variable of the inputHandler. It seems like awake() is called after OnValidate(). And that must have crashed something.
Answer by hexagonius · Jul 03, 2017 at 03:25 PM
If Awake really is not getting called, what you mention is not the issue. That would be terrible.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Update and Awake not being called. 1 Answer
why do these both codes work similarly when they are put inside update function... 3 Answers
C# Invoke Function with Params and Delay 3 Answers