Open Martin-PixelToys opened 3 years ago
Currently, we work around this issue by always instanciating via BoltNetwork.Instantiate. However, this is a major nuisance, since we can't keep Scene References inside Prefabs. Therefore, we have to make large refactorings when networking-up systems that interact with Scene Objects.
We have found a way to 'fix' things:
After doing that, 6 logs are printed as expected.
However, this was quite unexpected, since the repro project appears to have valid scene IDs and prefab IDs, even before we go through these steps. Also, we're worried that these issues may creep into our builds, potentially causing disasterious multiplayer issues. Therefore, we're considering adding additional build steps to ensure that 'Generator Scene Object IDs' has been called for every scene in the project, followed by a 'Compile Assembly'.
Please advice if this is something that is necessary, since it would add considerable time to our build pipeline.
Hi @Martin-PixelToys ,
Yes, Generate Scene Object IDs
is a necessary step if you are duplicating your Scene Objects and not including each one of them from the Project tab into your Scene.
When you duplicate a Scene Object already in the scene, it also duplicates the Scene Object ID, and running the Generate Scene Object IDs
either fix non-existent IDs and fixes the duplicate ones.
Using scene objects is not recommended, as they can lead to such cases, so we always recommend using object spawners, like it's shown in the Getting Started sample, for example.
Link: https://github.com/BoltEngine/Bolt-Sample/blob/master/GettingStarted/Scripts/InteractiveSpawner.cs
@ramonmelo For our use-cases we normally drag prefabs in from the Project tab. In our actual production project, we find that this usually causes Attach() to not be called, unless we use workarounds such as spawners, or manually calling Attach() inside our scripts.
We'd be okay with adding some Editor scripting that forces Generate Scene Object IDs
to be generated after saving a Scene, since this is a pretty fast operation, and being able to wire-up network objects directly in the scene is quite powerful, since it's possible to reference other objects in the scene directly, but this doesn't seem to fix our particular issue.
Hi @ramonmelo
I've managed to replicate the issues that we're seeing in our production project.
To Reproduce
Expected behavior I expected to see 6 logs, from 3 different instances (2 from scene objects, 1 from a runtime instanced prefab).
Actual behavior
I only see 4 logs. Base GO 2
from Scene 'Foo' that was loaded after calling BoltLauncher.StartSinglePlayer()
never gets attached.
From what I can tell, it looks like Bolt won't call Attach()
on SceneObjects that belong to scenes loaded after Bolt has been launched.
Using BoltNetwork.LoadScene
instead of SceneManager.LoadScene
appears to make the Attach() not called
issue go away, although it causes other issues for us in our production project, since we rely heavily on Additively Loading Scenes, which BoltNetwork.LoadScene
doesn't seem to support.
Hi @Martin-PixelToys ,
You must use Bolt API in order to keep things in sync, in this case, using BoltNetwork.LoadScene
will make your clients be always in sync with the server when it loads a new Scene.
And yes, one of the extra tasks of loading scenes using Bolt API is the auto attach for scene objects.
You can disable the Scene Auto Sync via the Bolt Settings (https://doc-api.photonengine.com/en/bolt/current/class_photon_1_1_bolt_1_1_bolt_config.html#af93c78289aa884e890244e9e822de111), if you want.
Unfortunately, Photon Bolt does not support additive scene loading, and if you need it, you will also need to manage other details manually, which includes either spawning the Entities when the scene is loaded or attaching them manually.
We also provide a Sample for Multi Scene loading here: https://github.com/BoltEngine/Bolt-Sample/tree/master/MultipleScenes Maybe you can use it as a base to implement your multi-scene project and include callbacks to spawn the entities, for example.
Describe the bug Bolt Entites are not attached if they're scene entities.
To Reproduce Steps to reproduce the behavior:
Expected behavior I expected to see 6 logs, from 3 different instances (2 from scene objects, 1 from a runtime instanced prefab).
Actual behavior I see only 2 logs, and only from the runtime instanciated prfab.
Repro project Here's a repro project: https://drive.google.com/file/d/1unvCd-Uj9EX7a_fNKcuVfH8EyAy86fer/view?usp=sharing
Desktop (If applicable, please complete the following information):
Additional context