Hi, I’m making a 2D endless runner for mobile where around every 5 seconds the spriteshape is edited to remove the points the player no longer sees and adds new points for the upcoming terrain. The problem I’m having is that whenever the new points are generated frames drop drastically.
I’ve been researching and found that there is a way to use Burst to increase performance but I can’t find any resources that explain how to do so. Alternatively, I also thought there might be a way to disable the spriteshape from updating unless I call the BakeMesh or RefreshSpriteShape methods to avoid it from doing any calculations until all the points required where added but I didn’t find any way to make it work.
Any suggestions on what direction I should take? Below is the simplified version of the script I made
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;
public class TerrainGenerator : MonoBehaviour {
public SpriteShapeController controller;
public float bleedThickness = 0;
public void GenerateSection (LevelLoader.SectionSettings settings, List<Vector2> points) {
RemoveEdges ();
for (int i = 0; i < points.Count; i++) {
controller.spline.InsertPointAt (controller.spline.GetPointCount (), points[i] - Vector2.up * transform.position.y);
}
CreateEdges ();
}
void RemoveEdges () {
// Remove Start
controller.spline.RemovePointAt (0);
// Remove End
controller.spline.RemovePointAt (controller.spline.GetPointCount () - 1);
}
void CreateEdges () {
// Create Start
float xPosStart = controller.spline.GetPosition (0).x;
controller.spline.InsertPointAt (0, new Vector2 (xPosStart, bleedThickness));
controller.spline.SetTangentMode (0, ShapeTangentMode.Linear);
controller.spline.SetTangentMode (1, ShapeTangentMode.Linear);
// Create End
int endIndex = controller.spline.GetPointCount ();
float xPosEnd = controller.spline.GetPosition (endIndex - 1).x;
controller.spline.InsertPointAt (endIndex, new Vector2 (xPosEnd, bleedThickness));
controller.spline.SetTangentMode (endIndex, ShapeTangentMode.Linear);
controller.spline.SetTangentMode (endIndex - 1, ShapeTangentMode.Linear);
}
}