Quantcast
Channel: Questions in topic: "crash"
Viewing all articles
Browse latest Browse all 2383

Why does this function, when called from OnDrawGizmosSelected, produce a different result and kill the editor?

$
0
0
It should be noted that I am using 5.3.5f1 due to that being the version available to everyone on the project (Uni PCs are a bit behind), if the only way to resolve this problem is to change version then I'll bring that up with the group. I've been *trying* to implement a gizmo to draw a curve in the editor to show the path defined by a series of game objects acting as nodes (in this case for a camera track), the path is calculated by the NewBezier function from the [Interpolate Class from the wiki][1]. This function works perfectly during runtime, as does the NewCatmullRom function which I use for another interpolated path, I don't doubt the class because the editor only started breaking when I started messing with Gizmos. To calculate the path I call this function: private void RecalculatePath() { sceneNodes = FindObjectsOfType(); // Get all CameraNodes in the scene nodes = sceneNodes.OfType().OrderBy(o => o.id).ToList(); // Sort by id into List nodeTrans = new Transform[nodes.Count]; int i = 0; foreach (CameraNode node in nodes) { nodeTrans[i] = node.transform; i++; } //running = false; seq = Interpolate.NewBezier(Interpolate.Ease(Interpolate.EaseType.Linear), nodeTrans, (float)((1 / speed) * nodes.Count)); sequence = seq.GetEnumerator(); Debug.Log("((1 / " + speed + ") * " + nodes.Count + " = " + ((1 / speed) * nodes.Count)); Debug.Log("Sequence length: " + seq.Count()); recalcPath = false; } This is called from my Start() function, and from OnDrawGizmosSelected() function which looks like: void OnDrawGizmosSelected() { if (recalcPath) { RecalculatePath(); } if (nodeTrans != null) { if (nodeTrans.Length >= 2) // Can't draw a path if there is only one node { //Draw control points for (int j = 0; j < nodeTrans.Length; j++) { Gizmos.DrawWireSphere(nodeTrans[j].position, 0.15f); } Vector3 firstPoint = nodeTrans[0].position; Vector3 segmentStart = firstPoint; foreach (var seg in seq) { Debug.Log(segmentStart + " to " + seg); Gizmos.DrawLine(segmentStart, seg); segmentStart = seg; } } } } (which is similar to the one in the example on the wiki page) *recalcPath* can be toggled from the editor. However the confusing part is that when the RecalculatePath function is called it logs the sequence length, and when the game is played normally this logs *1135* without fault. Yet when recalcPath is toggled from within the editor it logs *47* (sometimes it is closer to 300, don't know how to reproduce this though). I can only see this result though if I comment out the loop which iterates over the sequence and draws the path, because if I don't it just crashes the editor. Sometimes drawing a line (though I can't confirm if it's the correct path because it crashes), but it has crashed in previous versions of these functions without drawing anything. I'm completely stumped, nothing is created or destroyed when the scene plays and the only thing the camera nodes do when the scene plays is disable their sprite renderers. Any thoughts? [1]: http://wiki.unity3d.com/index.php?title=Interpolate

Viewing all articles
Browse latest Browse all 2383

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>