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 pizza_shark · Mar 16, 2014 at 11:54 PM · 2dtexturespriterender

Sprite rendering texture as one solid color

I have a texture that works fine when I render it using GUI.DrawTexture, however when I try applying it to a sprite through a script using:

var tile = new GameObject("Tile" + x + y); var sr = tile.AddComponent(SpriteRenderer); sr.sprite = Sprite.Create(texture, Rect(0, 0, 64, 64), Vector2(0, 1), 64);

it creates a sprite of the correct size at the correct location, but the sprite renders completely solid green(the most common color in my texture) rather than rendering the actual texture. Does anybody know why this might be?

Comment
Add comment · Show 6
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 robcbryant · Mar 17, 2014 at 12:11 AM 0
Share

Is this an editor window script or game script?

avatar image pizza_shark · Mar 17, 2014 at 10:59 PM 0
Share

A game script

avatar image robcbryant · Mar 17, 2014 at 11:24 PM 0
Share

Try messing around with the Texture / $$anonymous$$aterial settings in the inspector window -- like offsets and tiling if it's a $$anonymous$$aterial--this looks like an issue with the texture itself. You could try upping the size of the texture in the inspector window or fiddling with the texture type.

avatar image pizza_shark · Mar 17, 2014 at 11:32 PM 0
Share

I don't think it's an issue with the texture because it looks fine when I render it using GUI.DrawTexture(); I'll try messing around with the settings of the texture more though

avatar image robcbryant · Mar 18, 2014 at 01:06 AM 0
Share

try messing with the Vector2(0,1) pivot point -- I don't use Sprites so I'm not completely sure how it's handling the UV's etc. I started my project before Unity streamlined all of this. The docs don't define what the pivot point is or what it does--but I think changing to values enough times might show a difference--It may be 'pivoting' the sprite or offsetting it far enough to where only the green transparent pixels are showing. Try #s 1-64 and 0.1-0.9 in both the x and y in various combos.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Wuffles · Sep 16, 2014 at 04:51 AM

Had this same problem today with a Texture2D, disabling mipmaps worked for me. It seems like Sprite.Create was using a very low-res mipmap for some reason. If you can access your texture in the editor, you can disable mipmaps by going to the texture import settings, changing the Texture Type to "Advanced" and then unchecking "Generate Mip Maps".

Or if you're generating the texture in code, use a Texture2D constructor that lets you specify whether or not mipmaps are created, like this one (with whatever textureFormat you need):

 Texture2D tex = new Texture2D(16, 16, TextureFormat.ARGB32, false);

The "false" flag in that constructor tells unity to not generate mipmaps for the texture.

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

22 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

Related Questions

2D - How to make sprites repeat tiles? 4 Answers

Texture type -> Advanced -> Mesh type: how it works? 1 Answer

reset 2d animation(sprite sheet texture) 0 Answers

Tilling material on sprites it's not working correctly 1 Answer

How to break a sprite into shapes with script 1 Answer


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