|
Hi everyone, this seems pretty basic stuff, but I can't seem to get it to work for the life of me so I hoped maybe someone could show me the silly little thing I'm doing wrong to fix it. I want to build a doubly-linked-list of GameObject nodes that can be placed in the world. Each node has a next node, and a previous node. When I set an objects "Next Node" or "Prev Node" I want both objects to automatically point to each other (the user shouldn't have to go and change both nodes to correctly point to eachother). I can do this by hiding my NextNode and PrevNode members behind accessors, like so:
Now, I do want these nodes editable in the inspector. No worries, I can write an editor script. So I do:
But here's the problem, I'm expecting this (look at the highlighted Test)
But what I get is this:
Now I've seen other questions on the forums that ask this question too, and people recommended a TextField? But that's not really what I want here. Surely this is a reusable component right? How did the Unity developers do it? Thanks for your time,
(comments are locked)
|
|
It seems that the In the mean time, you can work around it by using a First of all, note that you have to make your variables serialized in order for them to be stored. All
Now, use a PropertyField to show the object field:
I have confirmed that to work fine. The scene objects are displayed. Note that using The root of the problem is that I would like to enforce that
Jan 19 '11 at 04:36 PM
Howard
The custom inspector I posted DOES use the properties and thus all assignment through the Inspector will ensure the list is linked correctly. I just remembered that you don't need to make the variables public either, you can use the [SerializeField] attribute instead. I have edited my answer to point this out.
Jan 20 '11 at 09:48 AM
runevision ♦♦
Thank you perfect!
Jan 20 '11 at 03:03 PM
Howard
(comments are locked)
|



Upvoted for the nicely formatted question, clearly asked, with screenshots to boot! I think this is a bug in Unity 3, but I hesitate to post that as an answer. BTW, the docs state that the ObjectField method "Make[s] an object drop slot field" -- does drag/drop from the Hierarchy work as expected?
Aside: rather than "if( target.GetType() == typeof( CameraNode ) )" it's clearer to write "if (target is CameraNode)".
ooh thank you! that's a good tip.
When I attempt to drag an object from the hierarchy I get the following error:
"InvalidCastException: Cannot cast from source type to destination type. CameraNodeEditor.OnInspectorGUI () (at Assets/Editor/CameraNodeEditor.cs:14) UnityEditor.InspectorWindow.OnGUI () (at E:/BuildAgent/work/71ca6fec1b41cc30/Editor/Mono/Inspector/InspectorWindow.cs:364) System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)"