- Home /
Component on SceneView camera has wrong gameObject In OnDrawGizmos.
Given this script attached to an empty object in a scene:
using UnityEngine;
using UnityEditor;
public class ThisSceneCameraTest : MonoBehaviour {
protected string cachedName;
void Start (){
foreach (SceneView window in SceneView.sceneViews){
if (window.camera.gameObject.GetComponent<ThisSceneCameraTest>() == null){
window.camera.gameObject.AddComponent<ThisSceneCameraTest>();
}
}
}
void Update(){
Debug.Log("In Update: " + gameObject.name);
cachedName = gameObject.name;
}
void OnDrawGizmos() {
Debug.Log("In OnDrawGizmos: " + gameObject.name);
Debug.Log("In OnDrawGizmos cachedName: " + gameObject.name);
}
}
The resulting output (during play) is: The output points to EmptyObject's OnDrawGizmos being called instead of the one on SceneCamera, but update indicates that that the script is definitely on SceneCamera. When the main camera is removed from the scene so no game cameras are rendering the output becomes:
So scripts on SceneCamera have their OnDrawGizmos tied to the MainCamera... but called from the object that added the script originally?
Can anyone explain this behavior?
Your answer
Follow this Question
Related Questions
How to hide Gizmos by script 4 Answers
Scene View perspective camera doesn't show girds and other gizmos 0 Answers
Select object by selecting gizmo or handle? 1 Answer
Turn Off Camera Frustum-Indicators In Scene View 2 Answers
Custom inspector draw Gizmos 0 Answers