首页 > 解决方案 > Unity Networking: Restore server objects on scene after change scene

问题描述

I use High-level API and I have a SceneA and SceneB.

SceneA has a couple spawned objects. After a new connection, each client receives objects list and spawn it.

But when I change networkScene A to SceneB and go back I see no objects on SceneA that were be rendered before.

Is there any solution how to get back to SceneA and refresh scene objects according to network SceneA instance?

In the SceneA I use something like this:

    public override void OnStartServer()
    {
        SpawnObjects();
    }

标签: unity3dnetworkingsceneunity3d-unet

解决方案


请记住,每次加载场景时都应该生成网络对象。

因此,如果它们没有“自动”生成,则可能是您没有设置任何逻辑来执行此操作。

所以工作流程应该是这样的:

  • SceneA 有一个预制件,当 Starts -> Spawner 时 SPAWNS 对象

  • 当玩家连接到场景时,将创建 Spawner,并在其 Start() 函数中生成东西。

  • 当你移动到场景 B 时,如果你没有设置 DonDestroyOnLoad() 之前的对象,将在 B 上消失

  • 但是如果你再次回到 A,因为游戏再次“创建”场景 A,spawner 将再次创建,并再次生成这些东西。


推荐阅读