Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 mirek_mazur · Nov 24, 2021 at 08:25 PM · arrayslistsdisplay

Displaying a List or an Array in Editor file

Hello everyone

I have a question about displaying a List or an Array After creating a List, I can add, remove or assign List items. The problem starts when I create the Custom Editor. I cannot assign a value to the list.

MonoBehaviour: RootTest.cs

 using System.Collections.Generic;
 using UnityEngine;
 public class RootTest : MonoBehaviour
 {
      [SerializeField] private List<GameObject> card = new List<GameObject>();
 }

.. and Editor: RootTestEditor.cs

 using UnityEngine;
 using UnityEditor;
 
 [CustomEditor(typeof(RootTest))]
 public class RootTestEditor : Editor
 {
     private RootTest myTarget;
     private SerializedObject soTarget;
     private SerializedProperty card;
 
     public override void OnInspectorGUI()
     {
         myTarget = (RootTest)target;
         soTarget = new SerializedObject(target);
         card = soTarget.FindProperty("card");
 
         soTarget.Update();
         ExecuteMenu();
         soTarget.ApplyModifiedProperties();
     }
 
     private void ExecuteMenu()
     {
         EditorGUILayout.PropertyField(card, new GUIContent("Card"));
     }
 }


I understand the problem is the Editor file which does not refresh the values. And the new item cannot be assigned.

Does anyone know how to do it ?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CodesCove · Nov 24, 2021 at 08:50 PM

One thing is that you should always start the OnInspectorGUI with serializedObject.Update().

Other thing is that you are doing unnecessary serializations. This way would be simpler..

 private SerializedProperty card;
 
 private void OnEnable()
 {
     card = serializedObject.FindProperty("card");
 }
 
 public override void OnInspectorGUI()
 {
     serializedObject.Update();
     EditorGUILayout.PropertyField(card, new GUIContent("ECard"));
     serializedObject.ApplyModifiedProperties();        
 }


Other that above things I don't see any problems

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 mirek_mazur · Nov 24, 2021 at 10:20 PM 0
Share

it works very well Thank you very much CodesCove

avatar image CodesCove mirek_mazur · Nov 24, 2021 at 10:34 PM 0
Share

Great to hear!

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

132 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

Related Questions

Copying lists cross-class not working correctly 1 Answer

Custom Inspector: For every new element in one array create a brand new array? 0 Answers

Inventory String error 1 Answer

How can you do calculations on two lists? 1 Answer

Creating a list using a list from another script? 1 Answer


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