- Home /
Do we need to call RecalculateNormals() if normal vectors are assigned?
Hi, I'm learning how to modify mesh in Unity3D. Following code is from the Unity website - Procedural example. I'm not really sure about it assigning normal vectors in the for-loop and then called RecalculateNormals() afterwards. I thought if it is calling RecalculateNormals() then it doesn't need to assign normal vectors in the for-loop. Am I wrong? Thanks!
// This script is placed in public domain....
// example code REDACTED to avoid propagation
// because it had incredible number of severe errors
Answer by Fattie · Oct 08, 2012 at 09:11 AM
no, you don't !
Unity's RecalculateNormals is just ONE WAY to decide on your normals.
It is one algorithm, offered for "free" by unity, for your convenience.
For example, I literally have two projects in front of me .. for one, it was adequate to just use Unity's RecalculateNormals. In the other, the engineers created the normals themselves - so unity's "recalculate normals" was irrelevant, and not used.
Re the code fragment above ... yes, you can comment away the line RecalculateNormals. It is a fact that whoever wrote that original code example, simply made a mistake.
(Just to be clear - there is another , unrelated, straightforward typo in that example code! See my long comment below on that.)
Also note Eric's critical comment below and bear that in mind!
dont forget the normals "have to be there", there has to be "something there" before you can use recalculatenormals.
Nope, RecalculateNormals() could in fact be called CreateNormals(). It will make normals out of thin air if necessary. All you need are vertices and triangles.
That example code has many, many problems! Notice the 4th and 3rd final lines of the Update(0 routine:
They build their own normals array named normals. But they accidentally set the .normals property to their variable named vertices!!
So, they are setting .normals totally wrong:
BUT everything still barely works, because, they (unnecessarily) run RecalculateNormals() !!!!!
(You could say, that example code is "both pointless, and wrong" :) )
This is an example in program$$anonymous$$g of where "one bad mistake masks another bad mistake."
SUGGESTION: we should always use clear variable names. Do not use variable names that look similar to other important words in Unity3D. Your own normals array should be called (for example) OurSpecialNormals, SimplestPossibleNormals, NormalsForDiscoLook, NormalsFor$$anonymous$$edeivalLook, or whatever is descriptive in your project.
I didn't noticed that typo! Thanks for the suggestion. :D
Your answer
![](https://koobas.hobune.stream/wayback/20220613082023im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Flat shading procedural generated mesh? 1 Answer
Triangles overlapping in mesh 0 Answers
Detail mesh normals sometimes flipped inside. 0 Answers
Preserving Mesh Normals and Smoothing 2 Answers
Mesh triagnles/surface with normals 1 Answer