Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnNetworkSpawn() is not called with specific enter play mode options enabled/disabled. #1879

Closed
maxsroka opened this issue Apr 16, 2022 · 3 comments · Fixed by #2720
Closed
Labels
stat:imported Status - Issue is tracked internally at Unity type:feature New feature, request or improvement

Comments

@maxsroka
Copy link

Description

OnNetworkSpawn() is not called on NetworkBehaviours under these circumstances:

  1. If Reload Scene and Reload Domain are disabled - OnNetworkSpawn will not be called just for the first time after scripts reload.
  2. If Reload Scene is disabled and Reload Domain is enabled - OnNetworkSpawn will not be called at all.

Reload Scene and Reload Domain are under the enter play mode settings in Projects Settings > Editor.

Reproduce Steps

  1. Add this script to a GameObject with a NetworkObject component:
using UnityEngine;
using Unity.Netcode;

public class Test : NetworkBehaviour
{
    public override void OnNetworkSpawn()
    {
        Debug.Log("OnNetworkSpawn() called");
    }
}
  1. Disable Reload Scene and/or Reload Domain in enter play mode settings.
  2. Enter play mode
  3. Start host

Actual Outcome

The message "OnNetworkSpawn() called" doesn't appear due to OnNetworkSpawn() not being called. If you disabled both Reload Scene and Reload Domain, the message will appear if you enter mode again without reloading scripts. If you disabled just the Reload Scene the message won't appear at all.

Expected Outcome

The message should appear in the console window.

Environment

  • OS: Windows 11
  • Unity Version: 2021.3.0f1
  • Netcode Version: 1.0.0-pre.7
@maxsroka maxsroka added stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report labels Apr 16, 2022
@will-mearns will-mearns added the stat:import Status - Issue is going to be saved internally label Apr 20, 2022
@ashwinimurt ashwinimurt added stat:imported Status - Issue is tracked internally at Unity and removed stat:import Status - Issue is going to be saved internally labels May 3, 2022
@ashwinimurt
Copy link
Contributor

MTT-3457

@lpmaurice lpmaurice removed the stat:awaiting triage Status - Awaiting triage from the Netcode team. label Jul 29, 2022
@NoelStephensUnity NoelStephensUnity added type:feature New feature, request or improvement and removed type:bug Bug Report labels Jul 29, 2022
@NoelStephensUnity
Copy link
Collaborator

@pixldev
I was able to replicate it with the domain reload being enabled and the scene reload being disabled.
When you disable the domain reload you can run into a myriad of issues if you exit playmode prior to completely shutting down NetworkManager as is demonstrated in the code example from InitializeOnEnterPlayModeAttribute where they manually reset their static defined integer (s_MySimpleValue). This is because when you exit abruptly with the domain reload disabled, whatever your static properties are set to will be what they are set to when you enter into play mode again.

With that in mind, the default settings for Unity are to have both domain and scene reloading enabled to assure that all of your classes are "reset back to the default state", the AssetDatabase is refreshed/updated, and then it reloads the scene, prior to serializing, in order to assure anything used by the scene is reloaded from the refreshed AssetDatabase.

Netcode for GameObjects v1.0 currently is designed to work with domain and scene reloading enabled (i.e. it works with the default settings). While I can understand that if you have a really large scene it could save development/debugging iteration time by disabling the reloading of the scene, and as such I am going to mark this issue as a feature request.

Before I do this, could you provide additional details as to why you would want either of the two options (domain or scene reloading) disabled and if it is blocking your project? (this will help the team determine the priority of this feature request)

@maxsroka
Copy link
Author

Before I do this, could you provide additional details as to why you would want either of the two options (domain or scene reloading) disabled and if it is blocking your project? (this will help the team determine the priority of this feature request)

Having these settings disabled saves a lot of time. It is a nice-to-have, but rather low priority. A warning that these are unsupported could be handy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:imported Status - Issue is tracked internally at Unity type:feature New feature, request or improvement
Projects
None yet
5 participants