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 CyberMew · Mar 04, 2014 at 05:41 PM · 2dtexturesprite

Sprite.Create is not working

 void OnPostprocessTexture(Texture2D texture)
 {
     GameObject go = new GameObject("TEST");
     SpriteRenderer sr = go.AddComponent<SpriteRenderer>();
 
     sr.sprite = Sprite.Create(texture, new Rect(0,0,500,500), new Vector2 (0.5f, 0.0f));
 }

The above sample code does not work properly. The sprite does not point to any Sprite texture. The SpriteRenderer's sprite points to none in the Inspector. However it seems like the data was valid while walking through the code. What is the problem here?

Comment
Add comment · Show 9
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 Loius · Mar 04, 2014 at 05:53 PM 0
Share

I use Sprite.Create succcessfully, so it's probably some weird issue. (0,0,500,500) means a box from 0,0 to 500,500; 0.5f,0.0f means the pivot will be top-center. Would these settings put the object out of view?

Is it possible to create gameobjects during the import process? That seems like an easy way to create memory leaks, perhaps Unity blocks it. Have you tried using a [$$anonymous$$enuItem("")] function?

avatar image CyberMew · Mar 05, 2014 at 07:31 AM 0
Share

I made it big so that I can see it easily. It creates a sprite which I would like to assign to a SpriteRenderer but it just points to nothing. Also the pivot point should point to the Bottom.

Yes it is possible to create gameobjects during the import process, but make sure you call DestroyImmediately to delete it once you are done. I am using it to create prefabs. I am trying to automate the import process to create prefabs so a $$anonymous$$enuItem won't do for me :(

avatar image CyberMew · Mar 05, 2014 at 04:38 PM 0
Share

I tried several code variations but it still doesn't work no matter what I do. It is like Sprite.Create is doing something funky with the texture. Even tried both OnPostprocessTexture and OnPostprocessAllAssets, same thing. Of course, it works great during runtime code, but that is not what we want.

If anyone is able to do Sprite.Create fine in these 2 functions, please post them as answers!

avatar image Loius · Mar 05, 2014 at 05:21 PM 0
Share

Of course it's bottom-center, why would we have any consistency in our coordinate systems. Consistency is for lazy people. [/sarcasm]

$$anonymous$$y only other suggestion is, is the texture a Sprite-type texture? You might need to do things with TextureImporter to be sure you have a Sprite texture to work with.

avatar image Dblfstr · Mar 05, 2014 at 07:10 PM 0
Share

What texture is actually being passed to the function? I do not know if you have it set in the inspector, or if you set it elsewhere? Are you trying to do this for a texture in a folder, automatically? Is the texture actually 500x500? Just looking for info.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Janibasha · Dec 27, 2017 at 11:41 PM

Rect rect = new Rect(0, 0, 8, 8); ==>> use 8x8 or as in ur error like 64x64 then Rect rect = new Rect(0, 0, 64, 64); ArgumentException: Could not create sprite (0.000000, 0.000000, 64.000000, 64.000000) from a 8x8 texture.

fbpic.sprite = Sprite.Create(result.Texture, rect, new Vector2(0f, 0f), 125);

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

23 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

Related Questions

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

Sprite Packer is always disabled [Problem] 1 Answer

How to get rid of dark line on the edge of transparent pixels? 2 Answers

Overlay texture on sprite 0 Answers

Replace a sprite by another in every game object using it 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