OnSceneGUI + TargetParameterCountException

Hi there…

I tried to implement a DrawLine to my Custim Inspector, to show the camera bounds in the scene view…
But i always get Errors.

This is the CustomInspector:

using UnityEditor;
using UnityEngine;
using System.Collections;

[CustomEditor(typeof(SC_Player_Holder))]
public class SCE_Player_Holder : Editor {

	SC_Player_Holder holder;
	Color rect1 = new Color(1,0,1);

	// Use this for initialization
	public override void OnInspectorGUI(){
		holder = (SC_Player_Holder)target;
		GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
		GUILayout.Label("Prefab für Staubwolken beim harten Aufschlagen.");
		holder.Particle_LandingDust = EditorGUILayout.ObjectField("Staubwolken Prefab:", holder.Particle_LandingDust, typeof(Object), true) as GameObject;
		
		GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
		GUILayout.Label("Die Kamera Werte um Scrollen außerhalb der Map zu verhindern.");


	}

	void OnSceneGUI(SceneView sceneView){
		HandleUtility.AddDefaultControl(GUIUtility.GetControlID(GetHashCode(), FocusType.Passive));
		Handles.color = rect1;
		Handles.DrawLine(new Vector3(holder.CameraMinimumX, holder.CameraMinimumY, 0), new Vector3(holder.CameraMaximumX, holder.CameraMinimumY, 0));
		Handles.DrawLine(new Vector3(holder.CameraMinimumX, holder.CameraMaximumY, 0), new Vector3(holder.CameraMaximumX, holder.CameraMaximumY, 0));
		Handles.DrawLine(new Vector3(holder.CameraMinimumX, holder.CameraMinimumY, 0), new Vector3(holder.CameraMinimumX, holder.CameraMaximumY, 0));
		Handles.DrawLine(new Vector3(holder.CameraMaximumX, holder.CameraMinimumY, 0), new Vector3(holder.CameraMaximumX, holder.CameraMaximumY, 0));
		Handles.color = Color.white;
		Handles.Label(new Vector3(holder.CameraMinimumX,holder.CameraMinimumY,0), "Camera Scroll Bounds");
	}
}

And this is the Error that appears a view hundret times…:

TargetParameterCountException: parameters do not match signature
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:188)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.SceneView.CallOnSceneGUI () (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/SceneView/SceneView.cs:1649)
UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/SceneView/SceneView.cs:1051)
UnityEditor.SceneView.OnGUI () (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/SceneView/SceneView.cs:928)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

At the same time, the Scene View standard controls at the top disappear…

What is wrong?

same here

If you necro an old thread with no additional information, then we’re stuck trying to diagnose some other person’s errors, which may or may not be the same as yours. Maybe he’ll come back and explain what had been wrong with his script, if he remembers after more than a year, but that still may not be the same as your problem.

If you have a problem/question, post your problem, with your code and the error copied over in [code ][/code ] tags, please.

When searching for this problem, it lead me to this thread. So I’m pasting the answer here for the next person…

If you’re defining a custom EditorWindow (which is a window not tied to a specific MonoBehaviour) then you need to declare your own method and hook it up to the SceneView changed delegate. Basically…

void OnEnable()
{
  SceneView.onSceneGUIDelegate += OnSceneGUI;
}
void OnSceneGUI(SceneView sceneView)
{
  // draw on the scene view here...
}

If you’re defining a custom Editor (which is a custom inspector window to replace the one generated automatically for you) then you just need to define a message handler…

void OnSceneGUI()
{
  // draw on the scene view here...
}

If you mix the styles (as shown in the first post) then when Unity calls OnSceneGUI it will find the wrong number of parameters.

1 Like