• 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 /
  • Help Room /
avatar image
0
Question by tntpadrone · May 01, 2017 at 08:31 PM · maintexture

Issue changing duplicated object texture

I have an object w$$anonymous$$ch has a mainTexture with a shader value of "Legacy Shaders/Transparent/Cutout/Diffuse". Upon Startup, I set the initial mainTexture and the cutout transparency works great.

Example:

       t$$anonymous$$s.GetComponent<Renderer>().material.mainTexture = Resources.Load("Images/ImageOne") as Texture2D;                        

Next, I am creating several duplicates of the original object and as long as I don't change the mainTexture, the cutout transparency sticks, but if I update the mainTexture by loading in a new png image similar to the way I did the initial image, the cutout transparency is removed.

Example:

         GameObject newObject;

         newObject = Instantiate(t$$anonymous$$s.gameObject, new Vector3(t$$anonymous$$s.transform.position.x,
                                                         t$$anonymous$$s.transform.position.y,
                                                         t$$anonymous$$s.transform.position.z  + Offset), Quaternion.identity);

          newObject.GetComponent<Renderer>().material.mainTexture = Resources.Load("Image/ImageTwo") as Texture2D;

I have tried copying over the original objects shader following the update to the image without success as well as various other t$$anonymous$$ngs.

Does anyone know how I can make the original shader implementation stay put after loading the new image or a way to update it back to the original objects shader so the transparency cutout will work?

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

Answer by tntpadrone · May 16, 2017 at 02:21 PM

I found the issue with t$$anonymous$$s. Unity docs describe how to do what I wanted to do (https://docs.unity3d.com/ScriptReference/Object.Instantiate.html) and so I was using the example to guide me in my implementation.

As it turns out, each time you create a clone in the Start() method, an additional Start is called. W$$anonymous$$ch is logical.

In the scenario where you are wanting transparency, there are issues with the nested Start() calls and the texture updates for the cloned objects.

What I did to fix t$$anonymous$$s was to only update the object texture if the ( gameObject.name == the original gameObject.name), thus preventing the cloned objects Start() method from updating the texture w$$anonymous$$ch allowed my initial object to perform the update to the cloned objects texture.

T$$anonymous$$s may seem a little odd, but I am creating objects dynamically to build a 3D model from a series of 2D image. It works pretty good and now I have transparency to form the 3D shape.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

99 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Adding a texture to a fresnel shader 1 Answer

Link Between Worlds picture mechanic 0 Answers

[HELP] Replicating the skybox effect with a Quad 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