Koderz
(Koderz)
October 17, 2016, 8:45pm
102
@ I’m not sure if I’ve found a bug or if this is just the way it is supposed to work.
For some reason CreateMeshSection() was failing to create a mesh, even though all the inputs were valid (I stepped though my C++ and inspected them). After calling it, the RMC was still showing as having no mesh sections internally. After hours of scratching my head and fiddling I eventually figured out that it has to do with the way you create the FBox bounding box. It turns out my FBox was not valid.
Here is the code I was using.
FBox Bounds;
Bounds.Min.Set(Start.X, Start.Y, 0.0f);
Bounds..Set(End.X, End.Y, Z);
Looks perfectly fine. However, the problem is that the internal FBox IsValid flag is not being set since I’m setting the Min/ directly rather than going through the FBox constructor. So I changed the code to this.
FBox Bounds = FBox(FVector(Start.X, Start.Y, 0.0f), FVector(End.X, End.Y, Z));
Now the IsValid flag is being set and CreateMeshSection() produces a mesh section. Great!
So my question… Is this intended? Seems odd that the mesh section isn’t created just because the IsValid flag was not set. It means you have to always create the FBox using one of its constructors. You can’t manually create an FBox.
This is indeed intended behavior. If the box is not valid, it can’t be used for culling and such so it will bail when it sees an invalid box. In editor it should log an error message, in a packaged game it will outright crash you. Those are picked up by the validation logic which can be found at the top of RuntimeMeshComponent.h
As for creating the box, there’s a couple ways to do it. First is like you just showed…
FBox Bounds = FBox(FVector(Start.X, Start.Y, 0.0f), FVector(End.X, End.Y, Z));
The next would be like you did originally with 1 addition.
FBox Bounds;
Bounds.Min.Set(Start.X, Start.Y, 0.0f);
Bounds..Set(End.X, End.Y, Z);
Bounds.IsValid = true;
The third way is useful when you just need to sum up the points and don’t know directly which is to do something along the lines of…
FBox Bounds(0);
Bounds += Point;
where ‘Point’ is a FVector point that the box needs to adjust to fit.
I hope that helped!