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 kalasc · Nov 10, 2016 at 12:35 PM · material renderer

FBX model material not changing (script)

In the editor I have dragged an FBX model into the scene, and a texture onto that. I have a script which does this in the start() function:

     [SerializeField] private GameObject m_world;

     // material at Assets/Resources/Materials/pic01.mat
     var m = Resources.Load("Materials/pic01", typeof(Material)) as Material;
     if (rend == null || m == null) Application.Quit();
     m_world.GetComponent<Renderer>().material = m;

This doesnt change the texture and I only see the original texture which I had set in the editor. What could I be doing wrong? The material I am loading was created in the editor. Here is what how the scene is arranged.

World

alt text

renderer.png (39.7 kB)
model.png (365.8 kB)
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

2 Replies

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

Answer by kalasc · Nov 10, 2016 at 03:41 PM

The problem turns out to be how I was referencing the model. For whatever reason the connection through the editor wasn't working, but I could get it to work by doing:

     gameObject.transform.parent.GetComponent<MeshRenderer>().material = m_materials[0];
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
avatar image
0

Answer by aditya · Nov 10, 2016 at 01:17 PM

do no use Renderer, use MeshRenderer

 m_world.GetComponent<MeshRenderer> ().material = m;

Accept if it worked

Comment
Add comment · Show 14 · 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 kalasc · Nov 10, 2016 at 01:36 PM 0
Share

doesnt help sorry, i updated the question with a picture of the setup if that helps

avatar image aditya kalasc · Nov 10, 2016 at 01:40 PM 0
Share

brother your $$anonymous$$esh Renderer component is disabled in inspector ... enable it

avatar image kalasc aditya · Nov 10, 2016 at 01:41 PM 0
Share

thats the mesh renderer on another object, not m_world which is the sphere

Show more comments
Show more comments
avatar image Desoxi kalasc · Nov 10, 2016 at 01:43 PM 0
Share

Replace the default material with a new created one and update the texture inside of it with GetComponent().material.mainTexture = someTexture;

avatar image aditya Desoxi · Nov 10, 2016 at 01:45 PM 0
Share

brother s/he is having problem with applying the material itself and not with texture

Show more comments
avatar image Desoxi · Nov 10, 2016 at 01:58 PM 0
Share

Are you sure, that the renderer you want to apply during runtime has the correct texture? $$anonymous$$aybe try to set the material in editor to none and just add the other pic1 material at runtime.

If your ressource management wouldn work, it would be null and according to your script the application should quit then.

avatar image kalasc Desoxi · Nov 10, 2016 at 02:03 PM 0
Share

it appears not, putting blank in editor and trying to set it at start() doesnt do anything

avatar image Desoxi kalasc · Nov 10, 2016 at 02:06 PM 0
Share

You should Debug.log somthing ins$$anonymous$$d of waiting for the app to quit, because Application.Quit() is ignored in the editor. If it logs something, then your material which you are trying to get with Ressorce.Load is not found.

Show more comments

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

change the color of 3DModel same as color of target image of vuforia AR in Unity 0 Answers

Why is my material not rendering properly 0 Answers

How to smooth imported objects 1 Answer

Material cant be seen until Im very close 1 Answer

Sprite Renderer Missing Material after running 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