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 duggulous · Aug 31, 2010 at 03:40 PM · prefabmaterialdisappear

Prefab loses its materials after running the game - Why?

In my Resources folder I have a prefab. That prefab has a few sub-meshes to which I want to apply a material/texture. So I assign a material by clicking the little black triangle next to "Element 0" in the Materials list & choosing a material. Then I save, and hit the play buttonplay button and test my game. Everything is fine. But when I return to the project view in Unity, my meshes no longer have a material. Element 0 says, "Missing (Material)". If I run the game again at this point, those objects have no materials or textures.

The result is I have to re-apply the materials every time I run the game. Can someone tell me what I have to do to make those materials permanent, so they don't get removed when I test the game?

Visual Aids:

Before: before

After: after

Note: I have a script that changes the texture on these meshes during the game. The code that changes the texture is:

myObject.renderer.material.mainTexture = www.texture;

where "www" is a WWW object.

However, I wouldn't expect that to affect the project files or settings. Am I missing something?

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
Best Answer

Answer by Eric5h5 · Aug 31, 2010 at 07:46 PM

You should only change instances of prefabs, not prefabs themselves. I would generally recommend not using Resources.Load unless you really have to, because you're more likely to make mistakes like that. Typically you do something like this:

var go : GameObject;

function Start () { var instance = Instantiate(go); instance.renderer.material.mainTexture = whatever; }

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 duggulous · Aug 31, 2010 at 08:39 PM 0
Share

So you're saying that it is in fact the script that is causing the material to disappear from the prefab?

If I need to dynamically create instances of the prefab at runtime, what better alternative is there to Resources.Load?

avatar image Eric5h5 · Aug 31, 2010 at 09:06 PM 0
Share

@duggulous: yes, it's the script. I edited my answer with some code.

avatar image duggulous · Sep 01, 2010 at 04:04 PM 0
Share

yep, changing the script fixes it. In your example I'm still not sure how to assign "go" to the prefab without using Resources.Load though...

avatar image Eric5h5 · Sep 01, 2010 at 06:48 PM 0
Share

@duggulous: drag and drop in the inspector.

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

No one has followed this question yet.

Related Questions

Reusing material on multiple prefabs, issues with tiling 1 Answer

Possible Unity Glitch. A few lines of code erasing prefab data. 1 Answer

change prefab material 2 Answers

Changing material with custom shader while instantiating prefab at runtime leads to change in color of all the instances 1 Answer

How can I assign an existing material to a prefab? 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