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 VildNinja · Nov 06, 2017 at 11:09 AM · editormaterialsceneviewdrag and drop

onMaterialChange or SceneView.onDropMaterial

Hi, I have a game object with many generated children. The parent does not have any visual or physical presence in the scene, only some code to maintain the children.

Our graphics artists are tired of having to assign a material on a field in the inspector, and would much rather be able to just use the regular drag and drop solution for setting materials. My problem is that I don't know how to detect this, without cycling through all children every frame, to detect changes.

Is there any onMaterialChange or SceneView.onDropMaterial? or just any drop event, so I can limit the check function to only run on those occasions.

/Jannek

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 pako · Nov 06, 2017 at 04:34 PM 0
Share

@VildNinja Could you please clarify the 2nd paragraph of your question. I mean, materials can be assigned in a field in the Inspector by drag-n-drop anyway, so it's not apparent (to me anyway) what exactly the problem is.

It does look like you want to detect a change of material, and I believe that you could setup a custom event to do that, but a lot of context is missing in your question.

So, please provide as much details as you can.

avatar image VildNinja pako · Nov 07, 2017 at 03:15 PM 0
Share

Sorry. The artists wants drag and drop in scene view. Dragging one material to one child should update the materials for all children. Currently the parent maintains a ref to the material, and has functionality to update all children. So I wanted any material drop events on the children to call that function on the parent.

I found a solution, so will post an answer now.

avatar image pako VildNinja · Nov 07, 2017 at 03:26 PM 0
Share

I see, so if I understand well, you want to have the flexibility to update the material, by drag-n-drop, either on the parent, or any of the children.

I don't know about you answer, but here's a suggestion: You could add an OnDrop$$anonymous$$aterial event to the child script, which I assume all children would have it assigned on them. Then, when any child gets a new material, it could raise the event. Since the parent has a reference to all the children, it could subscribe to the OnDrop$$anonymous$$aterial event of each child instance, and handle it appropriately.

The child script should be marked with the [ExecuteInEdit$$anonymous$$ode] attribute, and then in Update() check when the current material changes, in order to raise the OnDrop$$anonymous$$aterial event if it has.

Show more comments

1 Reply

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

Answer by VildNinja · Nov 07, 2017 at 03:22 PM

Hooking into the SceneView.onSceneGUIDelegate allows me to check for EventType.DragPerform and EventType.DragUpdated. Combining those with var mat = DragAndDrop.objectReferences[0] as Material; plus shooting a ray Physics.Raycast(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), out hit) allows me to steal the event and calling my custom function instead.

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

108 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

Related Questions

SceneView GUI - Add "Gizmos" IN Scene (not Overlay) 0 Answers

Material Color only changes when expanding material tab in inspector. 2 Answers

Material Array Using Custom Editor 0 Answers

Turn scene view "full screen" off 0 Answers

Is there a way to mass assign materials? 4 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