EditorGUILayout.ObjectField obsolete?

Hi guys

I am writing my first editor script, and I need a field for dragging in a prefab holding one of my classes.

Right now I am using EditorGUILayout.ObjectField and i works just fine; something like this:

target.myClass = EditorGUILayout.ObjectField("Label:", target.myClass, typeof(MyClass));

However, I get a warning in the console, saying that the function is obsolete, telling me to look at the docs for the usage of the new parameter ‘allowSceneObjects’. A similar massage is in the API docs:

EditorGUILayout.ObjectField

Googling allowSceneObjects has yielded no answers so far, so could someone fill me in on what is going on? I am using Unity 5 and C# scripts.

Use the recommended overloads instead. In your case:

target.myClass = EditorGUILayout.ObjectField("Label:", target.myClass, typeof(MyClass), true);

That true above tells the editor property to allow also scene objects. Set to false if you only want assets to be allowed.

When receiving a warning that the method or constructor is Obsolete, that is Unity’s way of saying that we no longer are going to support this method in future updates. AllowSceneObjects is a parameter of ObjectField().

Parameters

label
Optional label in front of the field.

obj
The object the field shows.

objType
The type of the objects that can be assigned.

allowSceneObjects
Allow assigning scene objects. See Description for more info.

options An optional list of layout options that specify extra layout properties. Any values passed in here will override settings defined by the style. See Also: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

Could you provide us with the exact warning. If this isn’t a pressing matter, these kind of warning can often be over looked. It is bad coding practice, but hey, Camer.mainCamera is still around after being obsolete for years!

Hopefully this might help someone, this is how I did it. Key is to have ‘true’ at the end.

GameObject fireEffect

--------------------------------------------- 

myDmgScript.fireEffect = (GameObject)EditorGUILayout.ObjectField("Fire Effect", myDmgScript.fireEffect, typeof(GameObject), true);

thanks your answers