Vrtk: BasePointerRenderer_Origin_Smoothed will be destroyed if VRTK is shared between two scenes

Created on 27 Feb 2017  路  10Comments  路  Source: ExtendRealityLtd/VRTK

Environment

  • Source of VRTK: Github
  • Version of VRTK: 3.1.0
  • Unity 5.4.4f1

Steps to reproduce

in my use case, I mark the camerarig game object as "don't destory on load"
this is the hierarchy of my camerarig
camerarig
VRTK is inside my camerarig, if I load another scene, "BasePointer_Origin_Smoothed" gameobjects will be destroyed

bug

Most helpful comment

Since my explanation above has helped a ton of people in Slack in the last days I think we should try to come up with something to handle scene changes/additive loading of scenes. :smile:

All 10 comments

Doesn't seem like an issue because:

BasePointer_Origin_Smoothed is only getting destroyed when your pointer is getting disabled. It will be recreated as soon as the pointer is enabled again.

well, in my case, [CameraRig] will not destroy when scene is changed, so OnDisable will not be called
it seams like I have to disable VRTK_BasePointerRenderer manually before load a new scene

It just now occured to me what you meant:
You set the CameraRig to DontDestroyOnLoad but the various created "helper game objects" like BasePointerRenderer_Origin_Smoothed (there are various others in VRTK) will be destroyed by changing the scene.

I don't think VRTK can handle scene reloads easily without changing the whole codebase. The easiest fix is to call SetActive(false) on your controller aliases before loading another scene. That will properly call all the OnDisable methods and therefore handle such things. As soon as you finished loading the new scene just call SetActive(true) on those game objects again.

If you use the same setup as the example scenes with a [VRTK] game object you child everything into you would just call SetActive on that [VRTK] game object. This will make sure you don't have to check every used VRTK script if they use such "helper game objects", it will just work because you disable everything.

(All the VRTK scripts basically disable/remove their needed stuff in OnDisable and enable/add them in OnEnable again. But if your scene switching shows that some scripts don't do that correctly - e.g. by only using Awake or Start instead of OnEnable - then let us know, please :smile:)

Since my explanation above has helped a ton of people in Slack in the last days I think we should try to come up with something to handle scene changes/additive loading of scenes. :smile:

This will probably be resolved by #817 soon.

Thinking about this some more it looks like #817 won't help because the "one SDK Manager for all the scenes" idea is still a good one.

Maybe we could add an internal VRTK helper class that manages those "helper game objects"? Perhaps by listening to scene changes and doing the same stuff that is done by disabling and enabling again?

Curious...is it a bad idea to make all of the helper objects also get DontDestroyOnLoad if the CameraRig has DontDestroyOnLoad ?

@sbmhome It's probably fine. But what happens if the user didn't have that flag set initially but later sets it at runtime? Or we check it and it's enabled but the user later disabled it?

As we've deprecated the Don't Destroy On Load from the SDK Manager, I think we should close this ticket as it's caused by the wider problem.

what do you think @bddckr ?

@thestonefox Agreed. I think this is no longer an issue if you follow the recommendation of per-scene SDK Managers or the additive scene approach. (Plus the SDK runtime switching brought us easy reload of scripts, so this should be no issue anymore. In fact we don't got any reports of issues like these anymore.)

Was this page helpful?
0 / 5 - 0 ratings