Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Glurth · Nov 15, 2017 at 08:11 PM · editorscriptableobjectnameserializedproperty

How to get "name" member of a ScriptableObject, as a SerializedProperty

In a test project I created a simple ScriptableObject:

 public class TestObj : ScriptableObject {
 
     public string description;
 
     [MenuItem("Assets/Create/TestObj", false, 10)]
     static void CreateTransitionSkin(MenuCommand menuCommand)
     {
         TestObj newObj = ScriptableObject.CreateInstance<TestObj>();
         
         newObj.name = "NewTestObject";
         newObj.description = "A whole bunch of words";
         AssetDatabase.CreateAsset(newObj, "assets/NewTestObject.Asset");
     }
 }

I then created a Custom Editor For the class:

 [CustomEditor(typeof(TestObj))]
 public class TestObjEditor : Editor
 {
     public override void OnInspectorGUI()
     {
         SerializedProperty nameProperty = serializedObject.FindProperty("name");
         SerializedProperty descriptionProperty = serializedObject.FindProperty("description");
 
         if (nameProperty == null)
             Debug.Log("Could not find property name, which is" + ((TestObj)target).name);
         else
             EditorGUILayout.PropertyField(nameProperty);
 
         if (descriptionProperty == null)
             Debug.Log("Could not find property description");
         else
             EditorGUILayout.PropertyField(descriptionProperty);
 
     }
 }

But when I create and inspect the object, the Editor fails to find the name Property and returns null. The console output is:

 Could not find property name, which isNewTestObject

Which shows that the name member exists and contains valid data, it just doesn't work with FindProperty.

Note: The description property IS found, and works/displays as expected.

I suspect the issue has to do with the fact that "name" is an inherited member from ScriptableObject, possibly (edit: confirmed it is) an accessor, and not a field. **What am I doing wrong / how do I make it work? (edit: confirmed it is an accessor, not a field, so that's what I'm doing wrong. Still, how do I make work? Sure I could just use a TextField, but I want all the undo stuff SerializedProperties support.)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Nov 15, 2017 at 10:00 PM 0
Share

This question certainly deserves a +1 as well. Questions like those are rare (well written, hasn't been asked a thousand times before, has actual relevance for others, is actually about Unity).

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by villevli · Nov 15, 2017 at 09:48 PM

The serialized property name is "m_Name".

 serializedObject.FindProperty("m_Name");

You can see the serialized fields of MonoBehaviour/ScriptableObject when you open your SriptableObject .asset file in a text editor. Editor Settings->Asset Serialization->Mode must be set to Force Text.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Nov 15, 2017 at 09:57 PM 0
Share

Exactly ^^. Great to see more people spreading some basic knowledge about the serialization system.

avatar image Glurth · Nov 16, 2017 at 03:59 AM 0
Share

Good thinking! I was totally going down the wrong track.

avatar image
0

Answer by eneroth3 · Dec 23, 2018 at 12:48 PM

If I'm not mistaken name is implemented at the Object level, and Unity may therefore not serialize it.

What I know the outdated Hungarian notation has nothing to do with this.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Glurth · Dec 23, 2018 at 07:27 PM 0
Share

the notation is irrelevant, the exact name of the field is what's needed. It IS serialized, as shown in the answer above, and indicated by the fact that the name persists.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

100 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Display Custom Inspectors for each class in a List<> 1 Answer

How do I associate my custom object for the serializedProperty objectReferenceValue 1 Answer

How to work with custom class (ScriptableObject) SerializedProperty? 1 Answer

Select custom object from a list via PopUp in custom editor for ScriptableObject 0 Answers

SerializedProperty.FindPropertyRelative returns null with ScriptableObjects 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges