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
1
Question by BugKiller · Jun 17, 2015 at 07:35 PM · editorprefabhierarchydetectdrop

Detect on Editor Mode drop prefab to the hierarchy

Hello,

I created one level design tool to create levels and I want to extend one feature. I have one feature that Adds an enemy wave to the current level, the game designer clicks "Add wave" button, it opens a panel (OpenFilePanel) to select the wave prefab and then in my editor script I load and instantiate the prefab as a child of the array object and add it to the correct wave array.

The new feature is to drag and drop the prefab from the "Project Window" to the array object on the "Hierarchy Window" and automatically add it to the array as I did before with the button + OpenFilePanel. I searched a lot for this feature from Unity but didn't find anything..

The game designer can do this by dragging the wave prefab to the hierarchy as a child of the array object but he has to switch to "Debug Mode" to add/drag manually the wave to the array and I want to skip this second process on the Debug mode.

The problem is that I need to identify when one prefab is dropped on the scene to check his parent and add it from the editor script to the array.

Another thing I would like to do, if I can detect the drag and drop operation, is to switch the order of the elements on the prefab. Currently I have two buttons on my editor script for each wave on the array to "move up" and "move down" on the array order but I also would like to do this when the game designer changes the order of the wave objects on the hierarchy. If I can detect a drop I can check the order of the objects on the hierarchy and fix it on the array.

There is a way to do almost this as I want, that is to have a button "Update waves" that checks the child objects of the array on the hierarchy and update the array, but still there will be a button for the game designer to press...

Thanks

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
2

Answer by winxalex · Oct 28, 2015 at 05:26 PM

This might give u an idea

Register callback handler

     EditorApplication.hierarchyWindowChanged -= OnHierarchyChanged;        
                 EditorApplication.hierarchyWindowChanged += OnHierarchyChanged;
             
 //Callback handler:
         private static void OnHierarchyChanged ()
         {

 if(Selection.activeGameObject!=null && PrefabUtility.GetPrefabType(Selection.activeGameObject)==PrefabType.PrefabInstance)
             Debug.Log (Selection.activeGameObject);


[1]: http://docs.unity3d.com/ScriptReference/EditorApplication-hierarchyWindowChanged.html

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 JeromeJ · Mar 11, 2018 at 03:42 PM 0
Share

How to easily distinguish between a mere re-ordering of an existing object in the scene VS a prefab has just been dropped in the scene now.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Text Labels For Prefabs in Hierarchy Turn Pink 2 Answers

keep gameObject in hierarchy folded when not selected 3 Answers

How Mark Prefab Dirty? 1 Answer

Can I force z position to match prefab when it's dragged onto scene? 1 Answer

Why do prefabs have redundant transforms? 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