Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Changing material offset clips end of sprite.

Discussion in 'General Graphics' started by ABernitt, Nov 29, 2023.

  1. ABernitt

    ABernitt

    Joined:
    Aug 19, 2023
    Posts:
    2
    I'm currently using a sprite with an unlit/transparent material attached in order to implement some parallax background scrolling. However, as the sprite is scrolled, part of the sprite is getting clipped on the right-hand edge.

    The video to show the effect in action is here:


    Finally, the code to do the scrolling is here:
    Code (CSharp):
    1. public class ParallaxBackground : MonoBehaviour
    2. {
    3.     [SerializeField] private float scrollSpeedRatio = 1.0f;
    4.     private Material material;
    5.  
    6.     private void Awake()
    7.     {
    8.         material = GetComponent<SpriteRenderer>().material;
    9.     }
    10.  
    11.     //This method should be called repeatedly in an Update method (see the ParallaxScroller class).
    12.     public void StepScroll(float speed)
    13.     {
    14.         float offset = Mathf.Repeat(material.mainTextureOffset.x + speed * scrollSpeedRatio * Time.deltaTime, 1.0f);
    15.         material.mainTextureOffset = new Vector2(offset, 0.0f);
    16.     }
    17. }
    I've also added some images in case they would be of any assistance:
    Clipped:
    clipped_sprite.png

    Normal:
    normal_sprite.png

    Any insights as to why this effect is occurring is greatly appreciated. Thanks!
     
  2. lilacsky824

    lilacsky824

    Joined:
    May 19, 2018
    Posts:
    172
    Is your Sprite is in Tight Mode? If so, it might be because it exceeds the Mesh when UV offsets.
     
  3. ABernitt

    ABernitt

    Joined:
    Aug 19, 2023
    Posts:
    2
    Sorry, this is the first time I'm hearing about "Tight Mode". What would that be?
     
  4. lilacsky824

    lilacsky824

    Joined:
    May 19, 2018
    Posts:
    172
    Hi, it is at sprite import settings.
    Try switching to Full Rect and see if it resolves your issue.
    螢幕擷取畫面 2023-12-01 104435.png