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
0
Question by DancingZombie · May 26, 2020 at 07:39 AM · scripting problem

Issue with EditorGUILayout.PropertyFeild

I am having trouble with List and the PropertyField on my custom editor inspector, I am using the following code which displays the list but i am unable to access it from the inspector in the unity editor, it is greyed out.

 [System.Serializable]
 public class Window
 {
     [SerializeField] public float Win_Width;
     [SerializeField] public float Win_Height;
     [SerializeField] public float Win_Depth;
     [SerializeField] public float Win_FrameSize;
     [SerializeField] public int HS;
     [SerializeField] public int WS;
     [SerializeField] public bool MultiSectionWidnow;
     [SerializeField] public Material GlassMaterial;
     [SerializeField] public GameObject Parent;
 }

 [CustomEditor(typeof(CreateWallScript), true)]
 public class CreateWallEditor : Editor
 {
     GameObject Parent;
 
     public List<Window> Win = new List<Window>();
 
     public override void OnInspectorGUI()
     {
         CreateWallScript CW = (CreateWallScript)target;
 
         ScriptableObject t = this;
         SerializedObject so = new SerializedObject(t);
         SerializedProperty stringsProperty = so.FindProperty("Win");
 
         so.Update();
 
         EditorGUILayout.PropertyField(stringsProperty,new GUIContent("Window Setup:"), true);
  
         so.ApplyModifiedProperties();
 
         Parent = CW.gameObject;
 
         if (GUILayout.Button("Create"))
         {
             CW.Clear();
             CW.Create(Parent, 3, 5, 0.1f, false, false, 0);
         }
     }
 }    

This is what is displayed, alt text

capture.png (17.4 kB)
Comment
Add comment · Show 2
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 Japsu · Sep 05, 2021 at 08:26 AM 0
Share

Did you ever happen to solve this? I'm facing similar issues.

avatar image andrew-lukasik Japsu · Sep 05, 2021 at 08:09 PM 0
Share

It is showing up as read-only because he tried to serialize CreateWallEditor : Editor, an editor window class (which is not even serializable), by mistake. The correct thing to do is to work with CreateWallScript component which is serializable just fine.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by andrew-lukasik · Sep 05, 2021 at 09:38 AM

These two lines are at fault here:

 ScriptableObject t = this;
 SerializedObject so = new SerializedObject(t);

Correct code:

 SerializedObject so = this.serializedObject;

CreateWallScript.cs

 using System.Collections.Generic;
 using UnityEngine;
 
 #if UNITY_EDITOR
 using UnityEditor;
 #endif
 
 public class CreateWallScript : MonoBehaviour
 {
     public List<Window> Win = new List<Window>();
     public void DoSomething () => Debug.Log("button works");
 }
 
 [System.Serializable]
 public class Window
 {
     public float Width, Height, Depth;
     public Material GlassMaterial;
     public GameObject Parent;
 }
 
 #if UNITY_EDITOR
 [CustomEditor( typeof(CreateWallScript) , editorForChildClasses:true )]
 public class CreateWallEditor : Editor
 {
     public override void OnInspectorGUI ()
     {
         var component = (CreateWallScript) target;
         EditorGUI.BeginChangeCheck();
         {
             EditorGUILayout.PropertyField( serializedObject.FindProperty(nameof(CreateWallScript.Win)) , new GUIContent("Window Setup:") , includeChildren:true );
             if( GUILayout.Button("Create") ) component.DoSomething();
         }
         if( EditorGUI.EndChangeCheck() )
             serializedObject.ApplyModifiedProperties();
     }
 }
 #endif
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 Japsu · Sep 06, 2021 at 03:57 AM 0
Share

This should be marked as the correct answer.

Thank you!

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

231 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 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 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

Check the material in script [C#] 1 Answer

Convert List of Floats to Colors (Color Map) 2 Answers

Why wont my script detect the input of my controller? 1 Answer

Script Not Working On Prefab 2 Answers

Grab and Drop Script goes through walls. 0 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