Koderz
(Koderz)
July 2, 2017, 2:23am
312
@ - So I’ve worked out what the problem is. It turns out you cannot set a material on a mesh section if that mesh section either doesn’t exist already or is not created in the same tick.
My actors add an empty RMC to themselves in the constructor. No materials or mesh sections are set at this point. Later on as the game dictates for a given actor, a material needs to be set and a mesh section needs to be created. The problem is that these two conditions are not met in exactly the same tick. For example, the player may choose a material and then it takes a few ticks before the mesh section needs to be created.
So the problem was that I was setting a material into slot 0 on the RMC, but I’m guessing slot 0 doesn’t exist as there is no mesh section yet. However if I force it to create the mesh section in the same tick, then it works fine. Even if I set the material before creating the mesh section. This explains why it would fail the first time and then work each time after that as the mesh section was now created.
Unfortunately, I cannot set the material and create the mesh section in the same tick. So to get around the problem I need to create a dummy mesh section in the constructor, so the RMC is not empty. To do this, I’m just using three vertices all at the world origin so they effectively make an invisible triangle and then create a mesh section from that. This ensures that material slot 0 exists and I can then set the material when needed. Later on, when the real mesh section is created, it simply overwrites the three dummy vertices.
So, not an ideal solution, but I can’t think of any other way around this issue. I’m not sure if this is a bug with RMC or just a limitation?
Thanks for the info! I’ll see what can be done in v3. Will probably need to figure out a way to fix that as v3 is being setup to explicitly handle creating empty sections for your type situations so that might actually become more of a problem without something to get around it.
On that note, I’m actually coming close to completing the core of v3! Will have more info soon!