Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
2
Question by peko · Dec 14, 2009 at 03:50 PM · instantiatematerialassetproject

How I can get an instace of a material, created in a project panel

I try to do this by myMaterial = Instantiate("MaterialName") and myMaterial = new MaterialName() But without any success.

I'm a novice and can't yet clear understand the poject panel paradigm. Can I access to objects in it? This objects, it`s classes or instances?

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

Answer by duck · Dec 14, 2009 at 04:19 PM

The project pane represents files on your computer, which have been placed in the 'Assets' folder of your project. These are files which are ready for use in your scene, but which may or may not have been used yet.

With normal use in Unity, you generally don't access these by name from script. Instead you drag references from your project view to various target destinations. You might drag a material directly on to an object in your scene (represented either in the scene view, or the hierarchy pane).

Or if you want to refer to a particular material in a script, you could create a public variable of type 'Material' in your script. This would expose the material variable for that script in the inspector, and you can then drag the material into that slot.

However, if you are placing a script on a GameObject which is visible in the scene, the chances are that object already has a material. You can refer to the material of the object on which the script is placed by using renderer.material like this:

renderer.material.color = Color.red;

Notice (as described in the docs) that accessing the object's material like this will actually create a temporary runtime clone of the material (thus making it unique to that object, even if it was initially shared by many objects in your scene). To affect all models which share a material use renderer.sharedMaterial like this instead:

renderer.sharedMaterial.color = Color.red;

hope this helps!

Comment
Add comment · Show 2 · 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 peko · Dec 14, 2009 at 04:38 PM 0
Share

Thank you very much! I better understand it now.

Reading mans, i find a class "Resources" what type of objects it supports? Can i Load predefined materials with it, or only textures?

avatar image duck ♦♦ · Dec 14, 2009 at 05:40 PM 0
Share

"Resources" is the class that you use to access assets which are stored in your Resources folder, in your Assets. I think it supports most kinds of assets. However, don't use the Resources folder for general purpose work - make sure you understand how to use drag-references and prefabs first, because this is how unity is designed to work. Items placed in Resources should only be there for special reasons, not just because you don't understand how to use Prefabs and dragged references!

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

Material doesn't have a color property '_Color' 4 Answers

Share material on Instantiate() 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Assetbundle materials? 1 Answer

Select all materials using a specific shader? 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