Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ungalyant2 · May 26, 2013 at 09:58 AM · propertiesediting

Multi Object Editing

I am creating a custom script editor where I wish to be able to edit multiple objects.

The key points as I understand them are:

-the [CanEditMultipleObjects] attribute is obviously required -I need to use a serialised property for each variable I wish to be able to edit on a multiple basis (I think) I'm a little unsure of exactly how serialised properties work, only that they do. -I am obtaining the serialised object from all targets OnEnable, and then finding the relevant properties for each property from this object. - I need to use serialisedObject.Update() and .ApplyModifiedProperties() at the beginning and end of my OnInspectorGUI.

My queries are: In all examples, properties are assigned in a way similar to this:

 EditorGUILayout.IntSlider(MyPropertyX, 0, 100);

Now without actually using MyPropertyX = before this statement, I am unsure as to how this is assigning the value to MyPropertyX.

On top of this whenever I try to do:

 EditorGUILayout.Toggle("My bool toggle", MyPropertyY);

The console throws an error stating that I need to use a bool, so properties can't simply used as bools? Meaning I am currently doing this.

 MyPropertyY.boolValue = EditorGUILayout.Toggle("My bool toggle", MyPropertyY.boolValue);

Without specifically assigning the value with the "=" then the value isn't changed when editing, this inconsistency between how the properties is assigned is confusing me somewhat.

Also as a last point, how do I achieve the same result as Unity's own multiple object editing where inconsistent values across multiple objects are represented by a dash "-" but I have no idea how this is achieved.

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
3

Answer by FlightOfOne · Apr 06, 2016 at 04:28 PM

I know this is an old post, and author probably found the answer.

I needed to know part of this question (your last point), and when I 'googled' this is where it brought me. Now that I have figured it out, here's how to do it. I think the official term for this is "Mixed Value".


 EditorGUI.showMixedValue = nameProperty.hasMultipleDifferentValues; //this turns on mixed value
 nameProperty.stringValue=EditorGUILayout.TextField(new GUIContent("Name "), nameProperty.stringValue);
 EditorGUI.showMixedValue = false; //If you don't want this to happen for the rest of the code



Click for more

Also, if I wanted the same for 'GameObject' or 'Transform', this is what worked for me.

  EditorGUI.BeginChangeCheck(); //This way change will only take effect if this code block changes
 EditorGUI.showMixedValue = rootProp.hasMultipleDifferentValues;
                 GameObject temp =EditorGUILayout.ObjectField(new GUIContent("Weapon Root"), rootProp.objectReferenceValue, typeof(GameObject), true) as GameObject;
 
 if (EditorGUI.EndChangeCheck())
      {
           rootProp.objectReferenceValue = temp;
      }


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

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

14 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

Related Questions

how do i change the color of basic water 0 Answers

Blender terrain in unity 1 Answer

Changing sprite properties at runtime 2 Answers

Get all exposed properties from all components 0 Answers

When is Awake called on an inactive gameobject 3 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