Unity was working as it should. I had two hidden scripts :/.
How are you determining that Awake is being called twice?
Agreed w/ A.Killingbeck, how do you know itâs being called twice?
Are you sure you donât have 2 of the same script attached to gameobjects in your scene?
A debug statement. New scene + empty game object + single script with (void Awake())
Thereâs probably just something weird Iâm doing. But putting a flag to make sure awake doesnât get called more than twice fixes it all. And I know thereâs not some strange second script somewhere cause the flag fixed it. If there were two separate scripts then I would have seen the message logged twice.
Thatâs just a bandaid⌠you should figure out why Awake is being called more than once. Because it shouldnât be.
Are you calling âSendMessage(âAwakeâ)â anywhere?
What does your code look like?
Nevermind. I wrote a search script which searched for any given script in the scene. Looks like I accidentally dropped the script on something else buried in the hierarchy so there were two instances (facepalm).
Hi.
Recently I also had such an issue.
Awake() was called twice when I exited from play mode.
After some research through SmartGit change-logs found out that the error was after I had added
[ExecuteInEditMode] for the Script.
I hope this will help others also.
My problem was the same, did you find a workarround to fix it without removing the [ExecuteInEditMode] ?
In my case it was ok to remove [ExecuteInEditMode].
But you can run the body of Awake() method only when application is in âplayingâ state.
private void Awake()
{
if (Application.isPlaying)
{
// Do Something
}
}
This comment just helped me 13 years later. I had twoâŚ
Unfortunately necroposting didnât help anyone else. Please donât do this, instead use the âLikeâ button to show your appreciation.
Thanks.
Thread Closed.
I saw the Awake can be called 2 times if itâs a class in a scene loaded with SceneManager.LoadSceneAsync