Issue
.
Defining an empty array of materials produces a populated array of newly instantiated materials that were never asked for.
.
Example:
Materials[] emptyMaterials = new Materials[10]; // <-- this is an empty array, 10 indexes long.
gameObject.GetComponent<MeshRenderer>().materials = emptyMaterials; // <-- this is now full
.
Apparently, materials
isn’t a simple field, rather someone wrote it as a property (since adding more overhead to every call is always faster than no code… [ha ha]). Funny thing, the original emptyMaterials
array is still empty. Assigning it didn’t actually update the reference at all. Unity simply loops over that and uses it as a suggestion, and then goes off to make an entirely new array on its own. That property loops through and fills it with entries when it finds a null.
.
I’m already trying to kill unnecessary new
calls in my own code. I am going to populate that array of materials eventually. The fact that the getter/setter is automatically volunteering this behind my back is quite vexing.
Tangential
.
- I’d like to submit a bug report, but it looks like this will need to start as an inquiry (read as: unable to submit bug report through “Issue Tracker”).
- The formatting of these questions is horrendous. Notice the periods, and note that they are there because these forums strip returns so as to reduce readability by implying that we have no paragraphs.
- This site is missing a decent syntax parser while composing questions (though it exists in the final post).
- Selecting a set of return-separated sentences to become a list simply strips the sentences of their return characters, adds one bullet, and inserts new returns at a column width of 36 characters.
- List items do not indent properly. Actually… they’re running off the page to the left by 1em. Seriously, who left the site in this state?
- The “Markdown Basics” tooltip states “basic HTML tags are supported”, yet it’s not responding to basic html markdown such as:
<font color="white">.</font>