Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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:
    170
    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:
    170
    Hi, it is at sprite import settings.
    Try switching to Full Rect and see if it resolves your issue.
    螢幕擷取畫面 2023-12-01 104435.png