Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screen View Camera Unexpectedly Re-Created #65

Open
jelling opened this issue Nov 22, 2022 · 0 comments
Open

Screen View Camera Unexpectedly Re-Created #65

jelling opened this issue Nov 22, 2022 · 0 comments
Assignees

Comments

@jelling
Copy link

jelling commented Nov 22, 2022

At various times we need to assign SceneCamera to objects so they can receive worldspace clicks. But the SceneCamera appears to be created multiple times on scene / layout load.

As a result, this happens:

  • SceneCamera is created for first time
  • OurClass.Canvas.worldCamera is assigned the SceneCamera.Camera
  • First SceneCamera is destroyed for some reason
  • Second SceneCamera is created
  • OurClass.Canvas.worldCamera is now set to an invalid camera

We patched this by checking the worldCamera for validity during the Update() loop, but that feels hacky.

Is there an event we can watch to know when the scene is done updating cameras? I tried AfterLayout but it doesn't help here

Also, is there a diagram somewhere showing the event sequences for when a scene loads or a layout changes? That would be helpful in understanding where we can hook into things.

SceneCamera created twice on initial editor load

I detected these events by pausing when gameObject.name == "SceneCamera"

Battlehub.RTCommon.RTECamera.Awake (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTCommon\Graphics\RTECamera.cs:134)
UnityEngine.GameObject.SetActive (Unknown Source:0)
Battlehub.RTCommon.RTEGraphics.CreateRTECamera (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTCommon\Graphics\RTEGraphics.cs:223)
Battlehub.RTCommon.RTEGraphics.CreateSharedMeshesCache (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTCommon\Graphics\RTEGraphics.cs:151)
Battlehub.RTCommon.SpriteGizmoManager.Start (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTCommon\Graphics\SpriteGizmoManager.cs:57)
Battlehub.RTCommon.RTECamera.Awake (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTCommon\Graphics\RTECamera.cs:134)
UnityEngine.GameObject.Internal_AddComponentWithType (Unknown Source:0)
UnityEngine.GameObject.AddComponent (Unknown Source:0)
UnityEngine.GameObject.AddComponent<Battlehub.RTCommon.RTECamera> (Unknown Source:0)
Battlehub.RTHandles.SceneGrid.Init (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTHandles\SceneGrid.cs:103)
Battlehub.RTHandles.SceneGrid.Start (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTHandles\SceneGrid.cs:67)

Scene Camera created twice on layout change

Battlehub.RTCommon.RTECamera.Awake (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTCommon\Graphics\RTECamera.cs:134)
UnityEngine.GameObject.SetActive (Unknown Source:0)
Battlehub.RTEditor.Workspace.OnTabActivated (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTEditor\Workspace.cs:1269)
Battlehub.UIControls.DockPanels.DockPanel.OnTabActivated (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\UIControls\DockPanels\DockPanel.cs:262)
Battlehub.UIControls.DockPanels.Region.OnTabToggle (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\UIControls\DockPanels\Region.cs:1607)
Battlehub.UIControls.DockPanels.Tab.OnToggleValueChanged (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\UIControls\DockPanels\Tab.cs:331)
UnityEngine.Events.InvokableCall<bool>.Invoke (Unknown Source:0)
UnityEngine.Events.UnityEvent<bool>.Invoke (Unknown Source:0)
UnityEngine.UI.Toggle.Set (c:\dev\studio\Library\PackageCache\[email protected]\Runtime\UI\Core\Toggle.cs:280)
UnityEngine.UI.Toggle.set_isOn (c:\dev\studio\Library\PackageCache\[email protected]\Runtime\UI\Core\Toggle.cs:243)
Battlehub.UIControls.DockPanels.Tab.set_IsOn (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\UIControls\DockPanels\Tab.cs:149)
Battlehub.UIControls.DockPanels.Region.Insert (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\UIControls\DockPanels\Region.cs:1345)
Battlehub.UIControls.DockPanels.Region.Insert (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\UIControls\DockPanels\Region.cs:1314)
Battlehub.UIControls.DockPanels.Region.Add (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\UIControls\DockPanels\Region.cs:1141)
Battlehub.UIControls.DockPanels.Region.Build (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\UIControls\DockPanels\Region.cs:777)
Battlehub.UIControls.DockPanels.Region.Build (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\UIControls\DockPanels\Region.cs:698)
Battlehub.RTEditor.Workspace.CoSetLayout (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTEditor\Workspace.cs:345)
UnityEngine.SetupCoroutine.InvokeMoveNext (Unknown Source:0)
UnityEngine.MonoBehaviour.StartCoroutineManaged2 (Unknown Source:0)
UnityEngine.MonoBehaviour.StartCoroutine (Unknown Source:0)
Battlehub.RTCommon.RTECamera.Awake (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTCommon\Graphics\RTECamera.cs:134)
UnityEngine.GameObject.Internal_AddComponentWithType (Unknown Source:0)
UnityEngine.GameObject.AddComponent (Unknown Source:0)
UnityEngine.GameObject.AddComponent<Battlehub.RTCommon.RTECamera> (Unknown Source:0)
Battlehub.RTHandles.SceneGrid.Init (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTHandles\SceneGrid.cs:103)
Battlehub.RTHandles.SceneGrid.Start (c:\dev\studio\Assets\Battlehub\RTEditor\Runtime\RTHandles\SceneGrid.cs:67)
@BattlehubCode BattlehubCode self-assigned this Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants