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 Biggerplay · Feb 01, 2015 at 09:56 PM · spritetexture2d

Clearing pixel from texture changes the asset as well?

My code creates a sprite texture from a asset. It then clears the bottom pixel of that sprite. That works fine, but what I don't get is that the actual itself that I created the sprite from also has a cleared pixel, and until I reset Unity it stays that way. So why/how is that happening? here's a screen shot Unity to show you what I mean. alt text

And here's the code I'm using that does that.

 backSprite = Resources.Load(assetName, typeof(Sprite)) as Sprite;
         
         //Create a new gameobject
         obj = new GameObject("RedSquare");
         
         //Attach a SpriteRenender to the newly created gameobject
         SpriteRenderer rend = obj.AddComponent(typeof(SpriteRenderer)) as SpriteRenderer;
         
         //obj.transform.position = new Vector2 (0, 0);
         
         //Assign the sprite to the SpriteRenender
         rend.sprite = backSprite;
         
         increment = 0;
         speed = 4;
         
         startPoint = transform.position;
         endPoint = transform.position;
         
         myTexture = backSprite.texture;
 
         MyPixel = myTexture.GetPixel(0,0);
 
         myTexture.SetPixel (0, 0, Color.clear);
 
         myTexture.Apply ();
screen-shot-2015-02-01-at-215026.png (104.3 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by hav_ngs_ru · Feb 02, 2015 at 09:56 PM

its funny behavoiur but yes, iit changes. But does not saves (so just reload your texture or all project - and you will see original texture, without changings).

create new texture, copy origin data to it and assign it to the object, as workaround.

I guess its feature, not a bug... but it still not obviously for me.

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

Answer by opponent019 · Feb 02, 2015 at 10:46 PM

Mmh if you're always gonna clear the same pixel then you could create another texture with that pixel missing from the beginning and change between those two when needed. If not, then try instantiating? Or look around for a reload sprite/texture command so that it can do it automatically or in the case that you need your complete texture again in-game.

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 Biggerplay · Feb 02, 2015 at 11:00 PM 0
Share

I ended up posting a connected issue in the forums http://forum.unity3d.com/threads/strange-issue-with-clearing-a-pixel-on-a-texture.295323/#post-1945791 I'm trying to figure out how to instantiate a texture and then a new game object, and set the texture to the game object and clear the pixel on that new version.

avatar image opponent019 · Feb 03, 2015 at 01:51 AM 0
Share

Oh then, I was right! :D I'm no pro with program$$anonymous$$g, still learning, so it feels good to see that hehe

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

21 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

Related Questions

How can I copy one sprite onto another based on world position? 0 Answers

Load Texture2D converted into Sprites; How can i add them to a GameObject sucessfully? 1 Answer

SetPixels/Apply: Texture2D resets on restart 0 Answers

Texture2D Power of 2 0 Answers

Image is crushed --- Sprite 2 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