Skip to content

SceneName in SceneEvent contains inconsistent values #3418

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

Open
Edvinas01 opened this issue Apr 23, 2025 · 4 comments
Open

SceneName in SceneEvent contains inconsistent values #3418

Edvinas01 opened this issue Apr 23, 2025 · 4 comments
Assignees
Labels
priority:medium This issue has medium priority and may take some time to be resolved stat:imported Status - Issue is tracked internally at Unity type:bug Bug Report

Comments

@Edvinas01
Copy link

Edvinas01 commented Apr 23, 2025

Description

When using automatic scene management, SceneName is inconsistently reported in NetworkSceneManager.OnSceneEvent.

Reproduce Steps

  1. Enable automatic scene management
  2. Subscribe to NetworkSceneManager.OnSceneEvent in networkManager.OnClientStarted
  3. Load a scene via NetworkSceneManager by passing in a full scene path (e.g., Assets/Scenes/GameScene_02.unity)
  4. Track SceneEvent.SceneName and SceneEvent.Scene arguments in OnSceneEvent callback

Actual Outcome

SceneEvent.SceneName in some event types contains the full scene path, in some only the scene name.

Expected Outcome

SceneEvent.SceneName should always be consistent - contain the full scene path or the scene name all the time.

Environment

  • OS: Windows 10
  • Unity Version: 6000.0.47f1
  • com.unity.netcode.gameobjects version: 2.3.2
  • com.unity.services.multiplayer version: 1.1.2
  • Distributed authority, using sessions

Additional Context

I'm using distributed authority:

var multiplayerService = MultiplayerService.Instance;

var options = new SessionOptions
{
    Name = multiplayerSessionNameId,
    MaxPlayers = 10,
    IsPrivate = false,
    IsLocked = false,
}.WithDistributedAuthorityNetwork();

await multiplayerService.CreateOrJoinSessionAsync(multiplayerSessionNameId, options);

Loading the scene as follows:

var scenePath = SceneUtility.GetScenePathByBuildIndex(index);
Debug.Log($"Starting to load scenePath={scenePath}");
sceneManager.LoadScene(scenePath, LoadSceneMode.Additive);

Tracking the OnSceneEvent the following way:

private void OnSceneEvent(SceneEvent sceneEvent)
{
    var sceneName = sceneEvent.SceneName;
    var eventType = sceneEvent.SceneEventType;
    var scene = sceneEvent.Scene;

    Debug.Log($"{eventType}: sceneName={sceneName}, scene.name={scene.name}, scene.path={scene.path}");
}

Log lines that get printed:

Starting to load scenePath=Assets/Scenes/GameScene_02.unity
Load: sceneName=Assets/Scenes/GameScene_02.unity, scene.name=, scene.path=
LoadComplete: sceneName=GameScene_02, scene.name=GameScene_02, scene.path=Assets/Scenes/GameScene_02.unity
LoadEventCompleted: sceneName=GameScene_02, scene.name=, scene.path=
@Edvinas01 Edvinas01 added stat:awaiting-triage Status - Awaiting triage from the Netcode team. stat:reply-needed Awaiting reply from Unity account type:bug Bug Report labels Apr 23, 2025
@EmandM
Copy link
Collaborator

EmandM commented Apr 23, 2025

The LoadScene() function takes either a path or a scene name. All other OnSceneEvent() events are explicitly invoking the event with only the scene name, however Load event on the authority instance (Server or DA host) will instead use the sceneName string that you passed into the LoadScene() function.

By calling LoadScene() as in your example above, the path that you are passing is what is being passed directly into the event.

Do you have further details on the issue you're encountering here?

@github-actions github-actions bot added stat:awaiting-response Awaiting response from author. This label should be added manually. and removed stat:reply-needed Awaiting reply from Unity account labels Apr 23, 2025
@Edvinas01
Copy link
Author

Edvinas01 commented Apr 23, 2025

The LoadScene() function takes either a path or a scene name. All other OnSceneEvent() events are explicitly invoking the event with only the scene name, however Load event on the authority instance (Server or DA host) will instead use the sceneName string that you passed into the LoadScene() function.

By calling LoadScene() as in your example above, the path that you are passing is what is being passed directly into the event.

Do you have further details on the issue you're encountering here?

Wouldn't it make more sense to make sure that sceneName is used in Load event, even if the user provides a scene path? This way each event type would be consistent in all cases. Now the alternative is that I have to treat the Load event separately (e.g., if I have List<string> loadingScenePaths in order to keep track of whats being loaded). I think this makes the API confusing as the variable name lies.

Alternatively I suppose to avoid breaking changes, perhaps documentation needs more clarification on this, since I was confused for a couple of hours when testing this as my loading state would hang as it was not cleaning up due to intermixed paths/names.

@github-actions github-actions bot added stat:reply-needed Awaiting reply from Unity account and removed stat:awaiting-response Awaiting response from author. This label should be added manually. labels Apr 23, 2025
@EmandM EmandM self-assigned this Apr 24, 2025
@github-actions github-actions bot added stat:Investigating Issue is currently being investigated and removed stat:awaiting-triage Status - Awaiting triage from the Netcode team. labels Apr 24, 2025
@NoelStephensUnity NoelStephensUnity added priority:medium This issue has medium priority and may take some time to be resolved stat:import Status - Issue is going to be saved internally and removed stat:Investigating Issue is currently being investigated labels Apr 25, 2025
@NoelStephensUnity
Copy link
Collaborator

That is a good point. The issue is marked for import.

For your use case (and to avoid potentially breaking other projects), would a reasonable compromise be to provide an additional "ScenePath" string within the SceneEvent so you have (consistently) the SceneName and ScenePath populated?

@github-actions github-actions bot added stat:awaiting-response Awaiting response from author. This label should be added manually. and removed stat:reply-needed Awaiting reply from Unity account labels Apr 25, 2025
@Edvinas01
Copy link
Author

That is a good point. The issue is marked for import.

For your use case (and to avoid potentially breaking other projects), would a reasonable compromise be to provide an additional "ScenePath" string within the SceneEvent so you have (consistently) the SceneName and ScenePath populated?

Having a ScenePath would be ideal I think!

@github-actions github-actions bot added stat:reply-needed Awaiting reply from Unity account and removed stat:awaiting-response Awaiting response from author. This label should be added manually. labels Apr 25, 2025
@EmandM EmandM removed the stat:reply-needed Awaiting reply from Unity account label Apr 25, 2025
@michalChrobot michalChrobot added stat:imported Status - Issue is tracked internally at Unity and removed stat:import Status - Issue is going to be saved internally labels Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:medium This issue has medium priority and may take some time to be resolved stat:imported Status - Issue is tracked internally at Unity type:bug Bug Report
Projects
None yet
Development

No branches or pull requests

4 participants