Skip to content

SetInScenePlaced marks runtime instantiated NetworkObjects as InScenePlaced #4118

Closed

Description

@ffejlersen

Description

A clear and concise description of what the bug is.

Reproduce Steps

  1. Go to 'NGO_Setup'
  2. Start play mode
  3. Click on 'Start Host'
  4. Click on the keyboard button "L" to load an additive scene with a spawner object
    • Console prints instance InScenePlaced state as False
  5. Click on the keyboard button "D" to print current state of spawned object
  • Console prints instance InScenePlaced state as True

Expected Outcome

Network objects instantiated during runtime should not be marked as InScenePlaced = true.
Before the introduction of SetInScenePlaced it was allowed to instantiate network objects from Awake.

Environment

  • OS: Windows 11
  • Unity Version: 6000.3.6f1
  • Netcode Version: 2.13.1
  • Netcode Topology: Client-Server

Unity Project

UnityProject.zip

Activity

  1. changed the title [-]SetInScenePlaced marks spawned NetworkObjects as InScenePlaced[/-] [+]SetInScenePlaced marks runtime instantiated NetworkObjects as InScenePlaced[/+] on Aug 6, 2026
  2. NoelStephensUnity commented on Aug 7, 2026

    @NoelStephensUnity
    Member

    Hi @ffejlersen,

    Thank you for your submission and the replication project as it greatly helped me narrow down the issue.

    If you dynamically instantiate something and then immediately disable the root GameObject, in order for any netcode related property to be accurate you will need to make sure:

    • The root GameObject is active in the hierarchy.
    • The NetworkObject has been spawned.

    Make this adjustment in your FooSpawner:

        private void Update()
        {        
            if (Keyboard.current.dKey.wasPressedThisFrame)
            {
                  // Enable it.
                _instance.gameObject.SetActive(true);
    
                 // Spawn it.             
                _instance.GetComponent<NetworkObject>().Spawn();
    
                // Log the netcode fields or properties you want to check
                Debug.Log($"{_instance.name} now has in-scene-placed value of: {_instance.GetComponent<NetworkObject>().InScenePlaced}");
            }
        }

    The related values of things that could be calculated during the spawn process are most likely not going to be accurate until it is spawned. The in-scene placed flag you are seeing when it is still disabled and not spawned lets us know you have pre-instantiated something into a scene, that is most likely still loading, and that (along with other information) allows us to determine that it should be treated as a dynamically spawned object. Once it is spawned, it should reflect the correct values.

    Let me know if this resolves your issue?

    Image
  3. added
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    and removed on Aug 7, 2026
  4. ffejlersen commented on Aug 11, 2026

    @ffejlersen
    Author

    Just to clarify our use-case.
    We have our own pooling implementation with NGO. We are seeing this, when we pre-warm our pools that are constructed before the IProcessSceneWithReport.OnProcessScene is invoked, but when the scene has been loaded.

    I haven't tried the suggested solution, but it seems to set the instances as active and spawns them? I guess they aren't ready for being spawned, since they are already marked as spawned?

    We have currently solved it by delaying the creation of them, or by providing a separate scene for inactive instances.

  5. added and removed
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    on Aug 11, 2026
  6. EmandM commented on Aug 11, 2026

    @EmandM
    Member

    Delaying the creation is a solid solution here.

    To explain what is going on here. We updated the marker of whether or not an object is "in the scene" from a nullable boolean to a boolean. The previous nullable boolean wasn't calculated until the object was first spawned which meant some of the edge case handling of "in scene placed" objects was inaccurate. That inaccuracy is why the SetInScenePlaced() function existed.

    As you've noticed, we moved the calculation from when the object is spawned to the IProcessSceneWithReport.OnProcessScene. The issue is, in the editor only, OnProcessScene will run after Awake has run on all objects in the scene. We were able to add checks to ensure we don't process any disabled object that is created in Awake. We also are able to skip any object that is created in a different scene and then moved into the current scene being processed.

    We're talking with the build team about providing a similar callback that doesn't run Awake first in the editor. They are working on it, but the CoreCLR related build changes are taking precedence at this time.

    We would be open to adding an equivalent to SetInScenePlaced that simply marks an object to be skipped by the OnProcessScene post-processor? We made this change hoping that manual configuration on the InScenePlaced variable wouldn't be needed. If it is needed then there's no reason to not add it back in.

  7. added
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    and removed on Aug 11, 2026
  8. ffejlersen commented on Aug 14, 2026

    @ffejlersen
    Author

    It is a bit of a hassle, since it introduces issues in the editor that isn't immediately evident about why it happens. It requires a bit of digging into the code to find the culprit.

    However, we just have to be aware that we aren't allowed to do any instantiation of network objects in Awake right after the scene has loaded.

  9. 2 remaining items

  10. added
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    and removed on Aug 14, 2026
  11. ffejlersen commented on Aug 17, 2026

    @ffejlersen
    Author

    Reference back to my prior answer:
    #4118 (comment)

    Also, we don't call Spawn() on them, since they aren't in use at that moment. The issue is that, due to IProcessSceneWithReport.OnProcessScene setting InScenePlaced to true, we get a series of despawn ids on the clients when they connect to the host, which throws warnings.

  12. added and removed
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    on Aug 17, 2026
  13. EmandM commented on Aug 17, 2026

    @EmandM
    Member

    Ok, thank you for the further information. Would it be useful to you to have a replacement for SetInScenePlaced(false) to be able to run this code in Awake? Or is moving the code a good enough solution for your use-case?

  14. added
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    and removed on Aug 17, 2026
  15. NoelStephensUnity commented on Aug 19, 2026

    @NoelStephensUnity
    Member

    @ffejlersen
    There is an update coming soon (v2.13.2) which should resolve this issue:
    When creating network prefab instances at runtime prior to starting a session will now be spawned as such (i.e. dynamic) and will not be spawned as in-scene placed. (#4093)
    Note about this:
    When not spawned, network prefab instances created prior to starting a NetworkManager/session could show InScenePlaced as "true" when not spawned (initially), but upon being spawned NGO figures out that it is really "a network prefab instance instantiated before it started" and dynamically spawns it.

  16. github-actions commented on Sep 3, 2026

    @github-actions

    This issue has been automatically marked as stale because it has been awaiting response for over 2 weeks without any activity.
    Please update the issue with any new information or it may be closed in 2 weeks.

  17. added
    StaleAdded after 30 days since stat:awaiting response was added (if it's still present)
    on Sep 3, 2026
  18. removed
    stat:awaiting-responseAwaiting response from author. This label should be added manually.
    stat:awaiting-triageStatus - Awaiting triage from the Netcode team.
    StaleAdded after 30 days since stat:awaiting response was added (if it's still present)
    on Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions