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 pepipe · Feb 12, 2016 at 01:43 PM · buttonserializedpropertycustom-editorcustomeditor

Extending unity UI Button problem

I have custom button that extends from UnityEngine.UI.Button, something like this:

 using UnityEngine;
 using UnityEngine.UI;
 using System;
 
 [Serializable]
 public class MyButton : Button {
   public float testFloat;
   public Image testImage;
   public Sprite testSprite;
 }

Then my editor class:

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEditor;
 using UnityEditor.UI;
 
 [CustomEditor(typeof(MyButton))]
 [CanEditMultipleObjects]
 public class MyButtonEditor : ButtonEditor {
   SerializedProperty floatProp;
   SerializedProperty imageProp;
   SerializedProperty spriteProp;
 
   public override void OnInspectorGUI()
   {
     serializedObject.Update();
 
     floatProp = serializedObject.FindProperty("testFloat");
     imageProp = serializedObject.FindProperty("testImage");
     spriteProp = serializedObject.FindProperty("testSprite");
 
     //Normal button options
     base.OnInspectorGUI();
 
     EditorGUILayout.PropertyField(floatProp, new GUIContent("Test Float"));
     EditorGUILayout.PropertyField(imageProp, new GUIContent("Test Image"));
     EditorGUILayout.PropertyField(spriteProp, new GUIContent("Test Sprite"));
 
     serializedObject.ApplyModifiedProperties();
   }
 }

My problem is that this code works on a new/clean project but when I add it to my project I can't drag or set values to the class variables. Even the float variable, that I can change on the editor, when I reload the scene the value isn't saved. So basically they appear on the editor but for Image and Sprite I can't set values and float I can change the value but does nothing...

At first I was setting the values directly like:

 component.testFloat = EditorGUILayout.FloatField("Test Float", component.testFloat);
 component.testImage = (Image)EditorGUILayout.ObjectField("Test Image", component.testImage, typeof(Image), true);
 component.testSprite = (Sprite)EditorGUILayout.ObjectField("Test Sprite", component.testSprite, typeof(Sprite), true);

Then I read that this will not work with prefabs and that is what I want.

The new/clean project is set to the same platform as my project. I spent a lot of time trying to figure why this doesn't work on the project that I want. I don't have any errors on console...

Anyone had a similar problem that can point me to a direction? My project has a considerable size so maybe is something that is creating a conflict but without any console error will be hard to know what.

Thanks!

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 pepipe · Feb 12, 2016 at 01:02 PM 0
Share

Well after some sleep and a clear head I found the problem. Our project still has EZGui, we are updating to the new UI, and EZGui have a Sprite class. So I needed to reference the right Sprite (UnityEngine.Sprite) to work.

I discover this after finding that float and image did work using the SerializedProperty. It wasn't working when I was messing the values directly and since my objects are prefabs it didn't store any value.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Editor Targets are updated but SerializedPropertys arent 1 Answer

Invalid iteration - (You need to stop calling Next when it returns false) 2 Answers

How might I go about creating a custom window similar to that of the Log window? 0 Answers

Horizontal Scrollbar shows up when Vertical Scrollbar appears 2 Answers

Getting CustomPropertyDrawer from SerializedProperty 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