- Home /
Prefab of SpriteShapeRenderer not rendered if first point not visible ?
Hello,
So my problem is that I have a prefab of a SpriteShapeController that I instantiate and generate points out of the field of view of the camera, and then it's supposed to appear in the field of view of the camera but the spriteShape is not rendered until the first point of the SpriteShape is in the field of view. After a long time of struggling and not understanding why the spriteShape were not visible (even in the scene view if the camera don't have in the field of view the first point the prefab is not visible in scene view) I came to this conclusion.
I don't really know what to do, maybe I'm not using well the SpriteShapeRenderer ? Does somebody already had this problem ?
Prefab :
The spriteShape only have 2 points in the prefab then at the Instantiation of the prefab i create more points in the script SpriteShapeManagerBrackground :
public void Start()
{
spriteShapeController = GetComponent<SpriteShapeController>();
previousPoint = spriteShapeController.spline.GetPosition(0);
newPoint = spriteShapeController.spline.GetPosition(1);
firstPoint = previousPoint;
for (int i = 0; i < 100; i++)
{
this.AddPoint();
}
}
And where I instantiate the prefab :
public void AddBackgroundPath(float y, float z)
{
GameObject go = Instantiate(toClone, new Vector3(this.cameraScript.camera.transform.position.x+ 250, y + UnityEngine.Random.Range(-200, 200), z), Quaternion.identity);
go.GetComponent<SpriteShapeManagerBackground>().camera = this.cameraScript;
}
I have the same issue, did you find a solution?
side note: I don't think you need the sprite renderer as the shape is rendered with the sprite shape renderer
Answer by RedHillbilly · Oct 29, 2020 at 08:50 PM
Found a possible solution by scrolling this thread: https://forum.unity.com/threads/tel...-with-sprite-shape.686305/page-3#post-6083610
But it only works if the shape doesn't change in time, otherwise you need to uncheck DestroyOnCompletion which might be heavy on computation.