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 Ariel J · Apr 11, 2011 at 06:15 AM · raycastmaterialrendererface

access material that is linked to face

Hi!

I wanted to ask this to see if it was possible!

Is it possible to get the material that is displayed on a face?

For example, I have a mesh with two materials. If I 'shoot' the mesh, can I see what material was assigned to that face?

Thanks,

-Aj

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
1

Answer by efge · Apr 11, 2011 at 10:48 AM

If 'shoot' the mesh means colliding with the mesh (detected by OnCollisionEnter or a Physics.Raycast) you can access the component(s) like this:

Graphics material used by the renderer:

collider.renderer.material

The Physics material is also available:

collider.material
Comment
Add comment · Show 4 · 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 Ariel J · Apr 12, 2011 at 12:14 AM 0
Share

Will this just default to the first material in the Renderers materials list?

Thanks for the response

-Aj

avatar image Kevin Ambruster · Aug 23, 2011 at 03:43 PM 0
Share

AJ did you ever get this to work. I'm trying to cast a ray against an object and return the material that is under the hitpoint. I can get the list of materials associated with the collider and of course the main/first material in the objects material list but not the material under the hitpoint.

avatar image Ariel J · Aug 24, 2011 at 09:22 AM 0
Share

I've been researching this recently, and found this page: http://forum.unity3d.com/threads/40377-Detecting-material-(material-index)-and-raycast-hit All you need to do to adapt this is use the hitSub$$anonymous$$eshNumber variable to get the index of the material on the hit object

Hope this is what you are looking for!

-AJ

avatar image Kevin Ambruster · Aug 24, 2011 at 01:57 PM 0
Share

That worked perfectly! Thanks for the heads up, saved us some time in having to split up all of our multiple material objects into separate objects.

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

2 People are following this question.

avatar image avatar image

Related Questions

Changing two different objects renderer colour 1 Answer

Changing texture with raycast on iPad 2 Answers

Are Mesh Filters Really Necessary? 1 Answer

Trying to make a side scroller. I'm following a tutorial and getting this error. 1 Answer

I want to paint the surface of a mesh depending on if it has been seen by a camera, can this be done with shaders? 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