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 pivot reset at script creation: camera transparency sorting problem (5.6.2p4)

Discussion in 'General Graphics' started by RhenaudTheLukark, Jul 24, 2017.

  1. RhenaudTheLukark

    RhenaudTheLukark

    Joined:
    Mar 11, 2016
    Posts:
    16
    Hello people! I'm posting a thread here because I encountered a weird bug while trying to order sprites using Camera.transparencySort.

    My goal here is to create sprites, and use the Camera's transparency sorting to display the sprites using their bottom. This is the code I used to change the Camera's transparency sorting. This code snippet is reached, as the priority is taken in account:

    Code (csharp):
    1. Camera.main.transparencySortMode = TransparencySortMode.CustomAxis;
    2. Camera.main.transparencySortAxis = new Vector3(0.0f, 1.0f, 1000000.0f);
    My system creates Sprite objects on the fly using that function:

    Code (csharp):
    1. Texture2D SpriteTexture = new Texture2D(1, 1);
    2. SpriteTexture.LoadImage(FileLoader.getBytesFrom(filename));
    3. SpriteTexture.filterMode = FilterMode.Point;
    4. SpriteTexture.wrapMode = TextureWrapMode.Clamp;
    5. Sprite newSprite = Sprite.Create(SpriteTexture, new Rect(0, 0, SpriteTexture.width, SpriteTexture.height), new Vector2(0.5f, 0), 100);
    Whether the sprites are created, I set it to a SpriteRenderer object (and not an Image object), but the sprite's info still says the Sprite object's pivot is Center:



    After some researches, I saw there was a solution with some buttons on the Editor but it doesn't seem to work either. Maybe I messed it up? I'll send an image just to be sure:



    Finally, this is what I have after all of this:



    And I'd really love to have that blue rectangle being displayed above the red rectangle, while it's bottom y position is above the red rectangle's bottom y position.

    Is there any way to achieve that? Did I screwed up something? Maybe you guys need more infos about my code and how I do things? Plase answer me as soon as possible, I'm on that problem for 4 day straight now :/
     
    Last edited: Jul 24, 2017
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Can't you just move it down in the hierarchy and let the UI RenderQueue voodoo take care of it? SetSiblingIndex ought to sort you...
     
  3. RhenaudTheLukark

    RhenaudTheLukark

    Joined:
    Mar 11, 2016
    Posts:
    16
    Argh, ouch. Sorry, it seems I messed up something in the presentation of my problem.

    For this kind of sprite, I don't use UI Images but SpriteRenderers.

    I use Images for other things in my project. Sorry for mixing up.



    This is what I have right now, several SpriteRenderer objects that I want to order by their bottom position.