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 15, 2012 at 09:20 AM · arraytexturesbatchsharedmaterial

batch textures, shared materials, instantiation, sharedmaterial array

how do you batch textures on game objects in JavaScript? say you have GameObject cubePrefab and 9 textures to apply to it as shared material-

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

Answer by MountDoomTeam · Oct 15, 2012 at 09:21 AM

this took me about 4 hours to find out as i am noob, I couldn't seem to find an answer for it and it's pretty unintuitive so here goes:

declare global variables

     var mymaterials = new Material[9];
     var sw1 : UnityEngine.Texture;//do this for 9 textures

in start function fill the multi-material array with different materials and give them the texture:

 var mat1 = cubePrefab.renderer.material;
 mymaterials[0] = cubePrefab.renderer.material;
 mymaterials[1] = new Material(mat1);
 mymaterials[2] = new Material(mat1);
 mymaterials[3] = new Material(mat1);
 mymaterials[4] = new Material(mat1);
 mymaterials[5] = new Material(mat1);
 mymaterials[6] = new Material(mat1);
 mymaterials[7] = new Material(mat1);
 mymaterials[8] = new Material(mat1);
 
 mymaterials[0].mainTexture = sw1;
 mymaterials[1].mainTexture = su1;
 mymaterials[2].mainTexture = sd1;
 mymaterials[3].mainTexture = sw2;
 mymaterials[4].mainTexture = su2;
 mymaterials[5].mainTexture = sd2;
 mymaterials[6].mainTexture = sw3;
 mymaterials[7].mainTexture = su3;
 mymaterials[8].mainTexture = sd3;


that's all you have to do! Afterwards, when you have a an instantiated prefab and you want to apply different batched textures to it do-

 stpc.renderer.material = mymaterials[1];
 stpc.renderer.material = mymaterials[9];


EDIT- draw calls 10, batched 468, FPS=120 :D

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 Kryptos · Oct 15, 2012 at 11:50 AM 0
Share

If you want to batch texture, I strongly suggest to use renderer.shared$$anonymous$$aterial.

Anyway your code does not batch anything at all. It just creates references to materials.

avatar image MountDoomTeam · Oct 15, 2012 at 12:30 PM 0
Share

I Does!!!!! i was dubious at first, I am testing it on a map, for example just now i have 10 draw calls, 468 batched :D. i just tried shared$$anonymous$$aterial on the last two lines abive, it does the same draw calls. it's using 6 for a skybox and 4 for the map walls..

One thing that was a major fault though, is that when i did an array of 12 materials mymaterials[12] i got a major error whereas mymaterials[9] worked fine, so there is a limit of 9/10 materials for 1 gameobject.

avatar image Kryptos · Oct 15, 2012 at 12:47 PM 0
Share

It only works because your must have enabled dynamic batching. But your script is not the cause of it.

avatar image MountDoomTeam · Oct 19, 2012 at 06:21 PM 0
Share

with either material or shared$$anonymous$$aterial, the combineChildren.cs script was able to merge hundreds of models into only one model per material, so it seems it re-uses the same material by either shared$$anonymous$$aterial and less likely by material, (it combinedchildren with both ) i tried to check if i ticked dynamic batching but i couldnt even find the option any more cos i started the project last year :S

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

Can you use a texture atlas as a colorpicker? 1 Answer

System.Type does not support slicing 1 Answer

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

InvalidCastException error and logic error 1 Answer

Attempting to change SetTexture("_DetailAlbedoMap", randomTexture) In children? 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