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 varunvp · Mar 24, 2015 at 06:02 AM · citysharedmaterial

How to make sharedMaterial work when I duplicate an object?

Hey Guys! You must have answered several of these questions, but all I want to know is how to make a material on a duplicated object change itself to another material which is on the original object. I am using a script to make a city with buildings of random heights. Here is a code snippet pertaining to setting the sharedMaterial.

 for(int x = 0; x < BuildingHeight; x++)
                 {
                     var Cube = Instantiate(BuildingTransform) as GameObject;
                     Cube.transform.position = new Vector3(BuildingPos.x, BuildingPos.y + BuildingScale.y * x * 2 , BuildingPos.z);
                     Cube.isStatic = true;
 //                    Cube.rigidbody.isKinematic = false;
                     Cube.tag = "Building";
                     Cube.transform.parent = transform;
                     Cube.renderer.sharedMaterial = BuildingTransform.renderer.sharedMaterial;
                 }

The materials of the others don't change when I change the material of the building transform object. I just need to know if I'm setting the shared material correctly? Can anyone tell me how to implement it for a simple duplicate operation and then for this script? Does sharedMesh come into play here? Thanks.

Comment
Add comment · Show 5
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 meat5000 ♦ · Mar 23, 2015 at 08:51 PM 0
Share

Access material, not shared$$anonymous$$aterial.

avatar image varunvp · Mar 27, 2015 at 11:22 AM 0
Share

That doesn't seem to work. There are still too many draw calls, approximately equal to the number of Cubes.

avatar image Jessespike · Mar 27, 2015 at 03:41 PM 0
Share

What version of Unity are you using? What material are you using? Is the BuildingTransform object a primitive cube or imported mesh?

avatar image hexagonius · Mar 27, 2015 at 04:45 PM 0
Share

Just instantiating the same object should dynamically batch. If you instantiate different prefabs, make sure they reference the same material already. Setting the isStatic flag only works prior to building. If you want to static batch the instantiated objects use the StaticBatchingUtility.

You were saying buildings of different height. Unless you were talking about different prefabs you didn't show you cannot batch them if you don't scale them uniformly. You can however batch buildings with the same uneven scale.

avatar image varunvp · Mar 29, 2015 at 07:23 AM 0
Share

@Jessespike: I'm using 4.6.3f1. $$anonymous$$aterial is a normal material with a mobile/Diffuse Detail shader. The Building Transform is an imported mesh. @hexagonius: So you mean to say that the high number (around 200) will not affect the performance if it batches dynamically? I have set this script to [ExecuteInEdit$$anonymous$$ode]. The city is not built in runtime. But I will try that StaticBatchingUtility though.

1 Reply

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

Answer by varunvp · Apr 09, 2015 at 11:41 AM

Hey Guys, I used Neodrop's script 'Combine Children Extented' to combine the children into one large mesh. This was able to bring the draw calls to a minimum(around 24 from 200). But be warned, this script will not be able to batch more than 64k vertices. Here is the link: http://forum.unity3d.com/threads/combine-children-extented-sources-to-share.37721/

Thanks Guys!

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

City making help 6 Answers

Isometric City Building Game 0 Answers

Finding and replacing all "instanced" materials 2 Answers

Spout: shared texture breaks model UVs 0 Answers

cityengine 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