Scene changing camera error

hello
trying to change scenes using this project Changing scenes | Learn PlayCanvas

i have 2 scenes, they are equal (i duplicated one scene from another)
some of my scripts use cameraEntity as an attribute
the problem is after switching, this camera entity doesn’t have property “camera”

like on screenshot (logs 1 and 2 are before switching, 4 and 5 after)
image

i guess this can happen because of “oldHierarchy.destroy()” in changing scenes script
but idk how it is possible

so the question is: why there is no property of camera and how to get this property?
thx

i think scripts are removed with hierarchy

because camera from second scene does not even have script property (but the same camera from first one has it)

is that possible to remove scene hierarchy without removing scripts?

or maybe scripts are loaded, but their attributes are not set…

Hi @Dima_Romanchuk ,

You are destroying the old hierarchy which means the camera and all of its components will be destroyed as well, if you want to pass over the camera entity to the next scene, that is possible by not destroying the whole root object, you can make a new root below the root entity and destroy that, eg

Root 
   oldHierarchy
Camera
   CameraEntity

The oldHierarchy has all the entities which are to be destroyed during scene transition,
Here, what you can do is this.app.root.findByName("oldHierarchy).destroy(); Now the camera won’t be destroyed as it is not part of the oldHierarchy.

If you are still facing any problem, feel free to post your project so I can take a look at it.

i meant camera from another scene didn’t apply when i switched to it

Yes because maybe it was destroyed? I would need to look at your script/project to help you further, I have written the steps to avoid destroying the camera when changing the scenes above.

but how can it be destroyed if it was not even loaded )
we load scene 2 from scene 1
scene 1 has camera 1, scene 2 has camera 2

so camera 1 destroyed, but camera 2 not applyed

Yes, in that case, camera 2 should work correctly, Please post a repro of the issue, so I can take a look at the issue and suggest you a solution, Thanks.