04-01-2014, 02:33 PM
Hello,
I'd like to use CurvySpline for path rendering. Therefore every entity (vehicle) has a CurvySpline attached, which I create in code at startup. When a new target is selected for the entity, I first do some pathfinding and then set the waypoints as the spline's control points. The process is as follows:
mSpline.Clear();
foreach(Waypoint waypoint in waypoints) {
mSpline.Add(new Vector3(waypoint .position.x * Map.TILE_SIZE, 0, waypoint .position.y * Map.TILE_SIZE));
}
mSpline.RefreshImmediately();
DrawPath();
At first time this works as expected. But on subsequent calls strange things happen. In Hierarchy View you can see the Spline Game Object, with child objects for each control point. In the Inspector View you can see that there are to many control points (amount differs from number of children in Hierachy View), so it seems like Clear() didn't really remove the control points. After a while I get "MissingReferenceException: The object of type 'CurvySplineSegment' has been destroyed but you are still trying to access it." when I call mSpline.InterpolateFast(). I tried to spread the calls on multiple frames, so first clear spline, next frame(next Update()-call) create new spline with Add(), next frame draw path. But that didn't help. So how's the correct code to change a spline at runtime? Should I use Clear() at all or just create a new spline?
I'd like to use CurvySpline for path rendering. Therefore every entity (vehicle) has a CurvySpline attached, which I create in code at startup. When a new target is selected for the entity, I first do some pathfinding and then set the waypoints as the spline's control points. The process is as follows:
mSpline.Clear();
foreach(Waypoint waypoint in waypoints) {
mSpline.Add(new Vector3(waypoint .position.x * Map.TILE_SIZE, 0, waypoint .position.y * Map.TILE_SIZE));
}
mSpline.RefreshImmediately();
DrawPath();
At first time this works as expected. But on subsequent calls strange things happen. In Hierarchy View you can see the Spline Game Object, with child objects for each control point. In the Inspector View you can see that there are to many control points (amount differs from number of children in Hierachy View), so it seems like Clear() didn't really remove the control points. After a while I get "MissingReferenceException: The object of type 'CurvySplineSegment' has been destroyed but you are still trying to access it." when I call mSpline.InterpolateFast(). I tried to spread the calls on multiple frames, so first clear spline, next frame(next Update()-call) create new spline with Add(), next frame draw path. But that didn't help. So how's the correct code to change a spline at runtime? Should I use Clear() at all or just create a new spline?