My English isn’t great, so I’m using ChatCPT for translation.
I referred to the AdditiveScenes scene.
The ideal operation is as follows: When the server presses Server, all game scenes are loaded, and objects on all scenes are generated. Players can also connect as clients to play. After objects are generated on the scene, they are set with parent hierarchy and position. When other clients connect, only the initially connected scene and the current game scene are loaded, similar to the AdditiveScenes example.
However, the current situation is that when the server also becomes a client, other players will encounter messages saying they can’t find the specified object (can’t find parent) after becoming clients. I’ve tried many methods but haven’t been able to solve this.
This script loads all scenes when the server starts.
![9832542--1414254--upload_2024-5-14_3-33-2.png](https://europe1.discourse-cdn.com/unity/original/4X/a/8/b/a8b56056d9a906df4b26958fd503e888d33382eb.png)
This script loads or unloads scenes upon triggering a trigger.
This script is a manager for object generation in the game scene.
This script synchronizes the positions of generated objects.
![9832542--1414266--upload_2024-5-14_3-37-29.png](https://europe1.discourse-cdn.com/unity/original/4X/a/6/e/a6eb3b2256d8086e1d3eb2cd4147fd1c28d4b141.png)
There are still some issues, but only five images can be posted in one article. I’ll continue in the reply.
The forum doesn’t allow posting .mp4 files, but I’ve posted the relevant videos on Discord.
Players can shoot bullets, and the survival time of the bullets is calculated by the server. After a few seconds or hitting a target, the bullets will despawn. However, if a player moves to another game scene before the bullets despawn, a message “NetworkObject for ObjectId of 40 was found null. Unable to despawn object. This may occur if a nested NetworkObject had its parent object unexpectedly destroyed. This incident is often safe to ignore. UnityEngine.Debug:Log (object)” appears. I can’t find a way to remove this message.
This script handles the timing and despawning of bullets.
I also just modified the bullet script to have the server despawn bullets. However, when changing scenes on the client side and the server deletes bullet objects, I get the message “NetworkObject for ObjectId of 40 was found null. Unable to despawn object. This may occur if a nested NetworkObject had its parent object unexpectedly destroyed. This incident is often safe to ignore. UnityEngine.Debug:Log (object)”. Although it doesn’t affect anything, I’d like to clear it.
Finally, following the script from the AdditiveScenes example mentioned above, when the server becomes a client and then stops being a client, the first scene is lost (the first scene includes lights and cameras).
When running the client for the first time.
When stopping the client.