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. Dismiss Notice

Resolved SpriteShape not getting rendered when enlarged

Discussion in '2D' started by FaithlessOne, Sep 7, 2023.

  1. FaithlessOne

    FaithlessOne

    Joined:
    Jun 19, 2017
    Posts:
    257
    Hello,

    I have an issue using the SpriteShapeController und SpriteShapeRenderer in Unity 2022.3.7 and com.unity.2d.spriteshape in Version 9.0.2. Without changing the spline of the SpriteShapeController it shows a white square. When the camera frustum does not show this white square initally when entering the playmode and a new created spline during runtime is set, which is much larger then the initial square, it is not shown then. It should at least be rendered a part of the sprite shape on the screen. But it seems that the initial kind of frustum culling is not invalidated when the shape changes. How to solve this issue?

    This is the code updating the spline of the SpriteShapeController:
    Code (CSharp):
    1. using System;
    2.  
    3. using UnityEngine;
    4. using UnityEngine.U2D;
    5.  
    6. namespace Screens.Various.Graphics1.Scripts
    7. {
    8.   public class SomeTestForSpriteShape : MonoBehaviour
    9.   {
    10.     private SpriteShapeController _spriteShapeController;
    11.     private SpriteShapeRenderer _spriteShapeRenderer;
    12.     private bool _wasSplineCreated;
    13.  
    14.     private void Awake()
    15.     {
    16.       this._spriteShapeController = this.GetComponent<SpriteShapeController>();
    17.       this._spriteShapeRenderer = this.GetComponent<SpriteShapeRenderer>();
    18.     }
    19.  
    20.     private void Update()
    21.     {
    22.       if (!this._wasSplineCreated && Time.unscaledTime > 5f)
    23.       {
    24.         var spline = this._spriteShapeController.spline;
    25.         var radius = 5;
    26.         float bezierTangentCircleCurveLength = 0.55228f * radius;
    27.    
    28.         spline.Clear();
    29.    
    30.         spline.InsertPointAt(0, new Vector3(0, 1 * radius, 0));
    31.         spline.InsertPointAt(1, new Vector3(-1 * radius, 0, 0));
    32.         spline.InsertPointAt(2, new Vector3(0, -1 * radius, 0));
    33.         spline.InsertPointAt(3, new Vector3(1 * radius, 0, 0));
    34.    
    35.         spline.SetTangentMode(0, ShapeTangentMode.Broken);
    36.         spline.SetTangentMode(1, ShapeTangentMode.Broken);
    37.         spline.SetTangentMode(2, ShapeTangentMode.Broken);
    38.         spline.SetTangentMode(3, ShapeTangentMode.Broken);
    39.    
    40.         spline.SetLeftTangent(0, new Vector3(bezierTangentCircleCurveLength, 0, 0));
    41.         spline.SetRightTangent(0, new Vector3(-bezierTangentCircleCurveLength, 0, 0));
    42.         spline.SetLeftTangent(1, new Vector3(0, bezierTangentCircleCurveLength, 0));
    43.         spline.SetRightTangent(1, new Vector3(0, -bezierTangentCircleCurveLength, 0));
    44.         spline.SetLeftTangent(2, new Vector3(-bezierTangentCircleCurveLength, 0, 0));
    45.         spline.SetRightTangent(2, new Vector3(bezierTangentCircleCurveLength, 0, 0));
    46.         spline.SetLeftTangent(3, new Vector3(0, -bezierTangentCircleCurveLength, 0));
    47.         spline.SetRightTangent(3, new Vector3(0, bezierTangentCircleCurveLength, 0));
    48.  
    49.         this._spriteShapeController.RefreshSpriteShape();
    50.    
    51.         this._wasSplineCreated = true;
    52.       }
    53.     }
    54.   }
    55. }

    Edit: Clarified the issue a bit more.
     
    Last edited: Sep 7, 2023
  2. DanielTanBK

    DanielTanBK

    Unity Technologies

    Joined:
    Aug 20, 2019
    Posts:
    80
    Venkify and FaithlessOne like this.
  3. FaithlessOne

    FaithlessOne

    Joined:
    Jun 19, 2017
    Posts:
    257