-
Notifications
You must be signed in to change notification settings - Fork 437
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
Null reference for : SceneManager.CheckForAndSendNetworkObjectSceneChanged(); in NetworkManager Class #3208
Comments
That error means that for some reason the NetworkManager is no longer valid. |
Hi @NoelStephensUnity I have a scene that contains a In the In the
The server then instantiates the desired player, accesses its Each time this process completes, the server checks how many players have spawned in the game. If the number of spawned players reaches the desired count, the server starts the game. The method
Additionally, there is a method named This is the entire process I follow. However, I encounter errors on Android, even though everything works properly in the Unity Editor. |
Hello again, So, I found the problem. - The code for loading the scene using Addressable:
- The code for loading the scene using SceneManager:
|
Ahhh...I understand now. So, if the addressable scene is not in the project's scenes in build list then this will be an issue as it will fail to properly synchronize and any netcode related assets within the scene won't be properly spawned on clients joining a session. The symptom should look like:
Currently, NGO only supports using addressable network prefabs. Now, if the addressable scene contains no netcode assets and is purely just visual related assets like terrain, models/geometry, environmental sound, music, and such... then that is perfectly fine. Look at this example to see how you can pre-load scenes. In the above example you will want to look at:
This will handle the loading "local" scenes portion. However, if you want to dynamically change what "local scene" is loaded then you will need to modify the above example a bit with something similar to the SceneBootstrapLoader with the adjustments (InGameAddressableSceneLoader):
Here is some pseudo code that shows a general direction of what I am describing: public class PlayerAddressableSceneLoaderStatus : NetworkBehaviour
{
public enum PlayerSceneLoaderStatus
{
None,
LoadingScenes,
ScenesLoaded
}
private NetworkVariable<PlayerSceneLoaderStatus> m_PlayerLoaderState =
new NetworkVariable<PlayerSceneLoaderStatus>(default,
NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
public void SetPlayerSceneLoaderStatus(PlayerSceneLoaderStatus playerSceneLoaderStatus)
{
m_PlayerLoaderState.Value = playerSceneLoaderStatus;
}
public override void OnNetworkDespawn()
{
if (IsServer && !IsOwner)
{
m_PlayerLoaderState.OnValueChanged += OnPlayerLoaderStateChanged;
}
base.OnNetworkDespawn();
}
private void OnPlayerLoaderStateChanged(PlayerSceneLoaderStatus previous, PlayerSceneLoaderStatus current)
{
if (current == PlayerSceneLoaderStatus.ScenesLoaded)
{
// Server knows the player has finished loading the addressable scenes
}
}
}
public class InGameAddressableSceneLoader : NetworkBehaviour
{
private PlayerAddressableSceneLoaderStatus m_PlayerLoaderStatus;
protected override void OnNetworkSessionSynchronized()
{
m_PlayerLoaderStatus = NetworkManager.LocalClient.PlayerObject.GetComponent<PlayerAddressableSceneLoaderStatus>();
// Start loading the addressable scene
base.OnNetworkSessionSynchronized();
}
private IEnumerator AddressableSceneLoading()
{
// Start loading your addressable scenes
m_PlayerLoaderStatus.SetPlayerSceneLoaderStatus(PlayerAddressableSceneLoaderStatus.PlayerSceneLoaderStatus.LoadingScenes);
var continueLoading = true;
while(continueLoading)
{
// loop until you are done loading scenes
yield return null;
}
// Notify the client is done loading the addressable scenes
m_PlayerLoaderStatus.SetPlayerSceneLoaderStatus(PlayerAddressableSceneLoaderStatus.PlayerSceneLoaderStatus.ScenesLoaded);
}
} |
### Description
I made an online game with NGO and it shows me a lot of null reference errors.
And this error only happens in Android and is not a problem in Unity!
With Android Logcat, I found out that the error is in the Unity NetworkManager script and from this part(Screenshots).
In Android, when the player enters the scene where the NetworkObject is located
In the scene, I have a script to connect to the server, this script works well in Unity
But such a problem occurs in Android
I have no idea where the problem is!!!
Can anyone help me, what is the cause of this error? Thank you.
Screenshots
Environment
The text was updated successfully, but these errors were encountered: