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 MountDoomTeam · Oct 14, 2012 at 04:12 PM · instantiatearraymultiplesharedmaterialmany

more efficient = gameObject w. Material[5] or 5x GameObject w. material[1]

take 200 instantiatios of a prefab with 5 textures.

if you use renderer.material to set your material, you get 200 instances of materials

If you do 5 different renderer.sharedMaterial you get one material maximum for all 200 instantiations, the last one applied.

you can't easily change texture on a prefab at all in code if you want to be computationally efficient. it seems impractical, you have to create five copies of the prefab with each material and then copy those copies. and if you do that, you have to instantiate new objects for the sake of duplicating the material even though you don't need them in the game to begin with. which is impractical.

So it seems simpler to make 5 prefabs all with different textures, and yet that's a long way around.

I think I have to make a new GameObject for each texture in code, and Instantiate different game objects.

in what way should a small number of textures be applied to many copies of a GameObject?copies of copies? make multiple root GameObjects? use multiple materials for each GameObject and then go through them with an array sharedmaterial?

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 · Oct 14, 2012 at 04:36 PM

An object with 5 materials is no more or less efficient (from a rendering standpoint) than 5 objects with one material each. It's can be more efficient to deal with in code, though, since you only have to move one object around instead of 5.

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 MountDoomTeam · Oct 14, 2012 at 06:27 PM 0
Share

Could you please tell me how to apply the multiple materials?

In start function i put this:

  cubePrefab.renderer.materials[0].mainTexture =sw1;
  cubePrefab.renderer.materials[1].mainTexture =su1;//[0]...[9]

what is the syntax to set a shared$$anonymous$$aterials from materials[]: in Update on different cubePrefabs?

thankyou!

avatar image Eric5h5 · Oct 14, 2012 at 07:28 PM 0
Share
 var materials = new $$anonymous$$aterial[9];
 materials[0] = x; // and so on
 cubePrefab.renderer.materials = materials; 

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

10 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

Related Questions

Instantiate an array of prefabs? 0 Answers

Instantiating prefab at child (spawnlocations are arrays) 2 Answers

Need to spawn a gameobject from an array 1 Answer

Array won't be filled by Instantiate 1 Answer

Instantiate problem with multiple objects from an array 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