Quantcast
Channel: Questions in topic: "exception"
Viewing all articles
Browse latest Browse all 470

How to properly catch Unity Assertion failures?

$
0
0
I have a custom mesh generation function. Depending on the data passed to this function, it might generate an Assertion Failure, which is displayed in the unity console:> Assertion failed: Converting invalid> MinMaxAABB> UnityEngine.Mesh:set_vertices(Vector3[]) The line that generate the assertion failure is: renderedMesh.vertices = tempvertices; Now obviously, this means there is a problem with the tempvertices provided to the mesh. I’m NOT looking for an answer on what conditions might generate such an assertion failure. My question is how do I catch it? (So I can display my OWN message in the unity console.) I have tried putting it in a `try-catch` block, just after setting the `[UnityEngine.Assertions.Assert.raiseExceptions][1]` flag (which appears to exist expressly for this purpose) to true, like so, but it had no effect on the output: UnityEngine.Assertions.Assert.raiseExceptions = true; try { renderedMesh.vertices = tempvertices; } catch (UnityEngine.Assertions.AssertionException e) { Debug.Log("Problem generating mesh for custom object: " + name + " . Aborting mesh generation."); renderedMesh.name = "Problem generating mesh"; return; } [1]: https://docs.unity3d.com/ScriptReference/Assertions.Assert-raiseExceptions.html

Viewing all articles
Browse latest Browse all 470

Trending Articles



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