Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Sprite.Create - bug in 4.6.3p3?

Discussion in '2D' started by jimmyo, Mar 15, 2015.

Thread Status:
Not open for further replies.
  1. jimmyo

    jimmyo

    Joined:
    Mar 20, 2014
    Posts:
    20
    I have Sprite.Create code that had been working just fine and recently upgraded to 4.6.3p3 and now getting an error message.

    myTexture is a texture of size 512x512

    code is:
    Texture myTexture = (Texture2D)Resources.Load ("paper512x512",typeof(Texture2D));
    myTexture.wrapMode = TextureWrapMode.Repeat;
    Sprite mySprite = Sprite.Create(myTexture, newRect(0,0,1024,1024), newVector2(0.5f,0.5f));

    Error is:
    ArgumentException: Could not create sprite (0.000000, 0.000000, 1024.000000, 1024.000000) from a 512x512 texture.
    UnityEngine.Sprite.Create (UnityEngine.Texture2D texture, Rect rect, Vector2 pivot)

    Any ideas? Is there something special I may have accidentally set to cause it to no longer tile properly?
     
  2. sthanedar

    sthanedar

    Joined:
    Jun 10, 2014
    Posts:
    2
    Did you ( or anyone else) find the solution to this issue? I just encountered the same error with ver 4.6.4f1. Earlier the sprite used to display !hasError message but the image was displayed. But now it shows the ArgumentException and the image does not load at all.
     
  3. mcowan

    mcowan

    Joined:
    Jun 7, 2015
    Posts:
    1
    I am getting this error in 5.1f as well. Ideas?
     
  4. Mooshoo-Labs

    Mooshoo-Labs

    Joined:
    Aug 21, 2014
    Posts:
    20
    Same here...
     
  5. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    This API has issues with certain platforms if the given Rect was larger than the provided texture. It was updated to raise this exception when a larger Rect is provided. We are working on an alternative solution for a tiling sprite.
     
    Deleted User likes this.
  6. jk34594345

    jk34594345

    Joined:
    Aug 15, 2015
    Posts:
    9
    Has there been any solution for this issue?
     
  7. tanaka-tai

    tanaka-tai

    Joined:
    Nov 5, 2014
    Posts:
    3
    I solved this issue in my case.

    error code:
    Sprite.Create(tex2D,newRect(0,0,Screen.width,Screen.height),newVector2(0,0));

    solved code:
    Sprite.Create(tex2D,newRect(0,0,texture2D.width,texture2D.height),newVector2(0,0));
     
  8. Peeling

    Peeling

    Joined:
    Nov 10, 2013
    Posts:
    401
    EDIT: There may be a work-around for this (not fully tested yet).

    When creating your sprites, scale the UV rect down by a power of 2 (say, 256.0f), scale down the 'pixels per unit' by the same amount, and then write a custom vertex shader that multiplies the UVs back up again. This will give you your tiling (which literally every hardware since the nineties can do just fine) without falling foul of Unity's nannying.
     
    Last edited: Aug 7, 2016
  9. iLyxa3D

    iLyxa3D

    Joined:
    Sep 25, 2013
    Posts:
    31
    Same error, when trying to create big sprite from small texture..
     
  10. TheMaster001

    TheMaster001

    Joined:
    Jan 29, 2018
    Posts:
    5
    Same Here, but then I just resized my texture to 640 x480 and it worked
     
  11. Albeoris

    Albeoris

    Joined:
    Oct 1, 2013
    Posts:
    11
    Hello from 2022.
    How I can create a sprite with different sprite.rect and sprite.textureRect sizes?
     
  12. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,802
    Nice. Please don't necro old threads. It's actually against forum rules, which you can see posted as the first post in this forum.

    Google is going to be your go-to for simple stuff like creating sprites and setting rects. If you have any other issues, START A NEW THREAD.

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220
     
    MelvMay likes this.
  13. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,563
    As above. Also, I believe we all know the current year so that's kind of redudant too.

    I'll lock this thread, it's run its course.
     
Thread Status:
Not open for further replies.