Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 sysameca · Jan 26, 2015 at 05:41 PM · editordrag-and-drop

Drag.Exited editor event confusion

I am trying to drag some game objects from the hierarchy window and drop them inside a rectangle field and automatically add them to a list. So my problem lies when trying to resize the SerializedProperty List which resides inside the inspected object, within the editor events. When trying to do a simple resize over the SerializedProperty "m_objectsList" like so:

     serializedObject.Update();

     if (current.type == EventType.DragExited)
     {
        Debug.Log("Drag Exited"); // Does get called.
        m_objectsList.arraySize++; // Does not resize.
        current.Use();
     }

     serializedObject.ApplyModifiedProperties();

the list does not expand. However when i switch the event for instance with MouseUp the array expands as expected.

    serializedObject.Update();

    if (current.type == EventType.MouseUp)
    {
       m_objectsList.arraySize++; // Resizes as expected
       current.Use();
    }

    serializedObject.ApplyModifiedProperties();

So even that the DragExited event get's performed it does not want to apply the modified properties? What is that i am missing and not understanding correctly.

Comment
Add comment · Show 4
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 Baste · Jan 26, 2015 at 07:51 PM 0
Share

Try a sanity check:

  if (current.type == EventType.DragExited)
  {
     Debug.Log("Drag Exited, arraySize: " + m_objectsList.arraySize);
     m_objectsList.arraySize++;
     current.Use();
     Debug.Log("arraySize now: " + m_objectsList.arraySize);
  }
avatar image sysameca · Jan 26, 2015 at 08:23 PM 0
Share

Did that already at the first place. It is increasing the array size by 1 but never shows that new element in the inspector and never resizes it more than 1 comparing to the $$anonymous$$ouseUp event which normally increases the array.

avatar image sysameca · Jan 26, 2015 at 08:33 PM 0
Share

The array size get's 0 as soon as the OnInspectorGUI() code finishes execution and starts again it's next frame.

avatar image Moe_Baker sysameca · Jun 08, 2021 at 07:56 PM 0
Share

6 years later and I'm getting screwed by this now, almost at the point of pulling my hair. One thing I found is that after DragExited is called, shortly after an Undo event very precisely will be called by God knows what to specifically nuke any changes you have made during that DragExited call, I swear to GOD it's like someone at Unity is just trolling us at this point.

2 Replies

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

Answer by sysameca · Jan 27, 2015 at 06:52 AM

So i will write what i did if somebody else ever needs this. It seems that for some reason when trying to perform some action over a SerializedProperty inside the if (current.type == EventType.DragExited) brackets, when dragging from the hierachy window to some inspector item, does not apply the modified properties of the serialized object. As i though what can i simply do, i came up with a bool flag to check when the drag exits and just do my logic inside the EventType.Repaint:

 private bool m_dragExited;

 public override void OnInspectorGUI()
 {

 serializedObject.Update();

 if (current.type == EventType.DragExited)
 {
    if (position.Contains(m_mousePosition))
    {
       m_dragExited = true;
    }
 }
 
 if (current.type == EventType.Repaint && m_dragExited == true)
 {
   // Perform whatever action needs to be done when the drag exits
   m_dragExited = false;
 }

 serializedObject.ApplyModifiedProperties();
 }

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 Baste · Jan 27, 2015 at 12:54 PM 0
Share

Could you post a bug report about this?

avatar image
1

Answer by Moe_Baker · Jun 08, 2021 at 08:23 PM

Very old thread but I wanted to answer it since I have been pulling my hair with this problem for a good day.

DragExited is meant to be used for when a drag is canceled (like when the user presses escape when dragging) so in a sense, it really should've been called DragCancelled instead, and to add insult to injury, if you were to use the DragExited event type then shortly afterward a very mean & silent undo operation will be invoked to undo all of the changes you made, so it will make it seem as if the changes are applied but then they disappear three frames later ....

DragPerform is what gets called when the drag is "performed" which any reasonable person would assume to be when an object is first dragged, but you see it's actually called when the drag operation is completed, so you'll need to use that instead.
Thank you for wasting a day of my life Unity, hopefully, this information saves someone else from wasting their time as well.

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

21 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

Related Questions

DragAndDrop class 1 Answer

Can't drag and drop assets to editor. 6 Answers

Possible to drag items across tabs onto the same frame? 1 Answer

Drag & Drop Components in the Editor 1 Answer

drag and drop 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