- Home /
The question is answered, right answer was accepted
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:
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.
Answer by frarees · Apr 09, 2015 at 09:04 AM
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.
Answer by FlightOfOne · Mar 09, 2016 at 12:59 PM
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);
This answer doesn't add anthing useful. The question has already been answered in april 2015 by frarees. He also explains what that new last parameter is good for which you didn't even mention. You just bumped the question
I was trying to figure out how to make it for a GameObject. Thanks!!!!
Answer by KitoCode · Apr 09, 2015 at 10:16 AM
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!
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Is it possible to create sound with scripting? 4 Answers
How do I make the platform spawn after the other one 1 Answer
How to keep the old line text? 1 Answer