Awake not being called on NetworkBehaviour Component
Describe the bug Awake is not called on objects with NetworkBehaviour unless server/host/client is started.
Reproduce In "Basic" example, open scene. Create an empty object in scene. Create a test.cs file with the following code:
using Mirror;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : NetworkBehaviour
{
private void Awake () {
Debug.Log ("awake called");
}
}
Attach component to created gameobject
Start scene in editor.
Look at the console output, this should be there:
Next, Build this scene with that settings:
Then, run the resulting build.
Then close the game application.
Next navigate to:
C:\Users\YourUser\AppData\LocalLow\YourCompany\YourProjectName\ on your windows computer
Open file Player.log
Understand that there is no "awake called" message.

Expected behavior Expected "awake called" message in Player.log file
Desktop:
- OS: Windows
- Build target: standalone
- Unity version: 2021.3.5f1 Personal
- Mirror branch: idk, I just downloaded from asset store. Mirror version: 66.0.9
Additional context I need Awake in order to create singleton. I would appreciate any other solution, however this is very odd that Editor and Build versions behaves differently.
I faced this issue as well. Very annoying when Editor and Build behavior is different. Hope it gets fixed soon.
My understanding is that Mirror disables all GameObjects inside a Unity scene with a NetworkBehaviour on them. It then re-enables them on each client once they have been spawned. This is documented here.
In your case, unfortunately, since the no client / host is started, the GameObject never gets enabled.
thanks for the detailed report :)
as @Ikalou mentioned, scene objects are only loaded once they are spawned. until then, they are meant to behave similar to prefabs (=unloaded).
this is because we don't want their awake/update/etc. to run before spawned. for example, a scene object monster on the client should not move around before it was even spawned over the network.
this isn't strictly necessary, but we figured it makes most sense this way. do you think it should be changed?
do you think it should be changed?
Well, I don't think it should be changed and now I understand why this is needed, however, in my opinion it's not good when Editor and Build behaviour is different.