I’ve got a simple setup, which looks somewhat as the following: ( Bear in mind that I just started today with Unreal Engine, so the setup is most likely horrible )
I’ve got a class called VFTerrain, like so:
UCLASS(ClassGroup = Rendering)
class ... AVFTerrain : public AActor
{
GENERATED_BODY()
protected:
// Cell Mesh List
TArray<UVFMesh*> m_vCellMesh;
.....
Just to test, I create the class VFMesh like so:
.....
pCell = ConstructObject<UVFMesh>(UVFMesh::StaticClass(), this, "VFTerrainCell");
pCell->RegisterComponent();
pCell->Create();
{
// Generate cute plane
TArray<FProceduralMeshTriangle> Tris;
Tris.Add(FProceduralMeshTriangle(
FProceduralMeshVertex(FVector(0, 0, 0)),
FProceduralMeshVertex(FVector(1, 0, 0)),
FProceduralMeshVertex(FVector(0, 0, 1))
));
Tris.Add(FProceduralMeshTriangle(
FProceduralMeshVertex(FVector(0, 0, 1)),
FProceduralMeshVertex(FVector(1, 0, 0)),
FProceduralMeshVertex(FVector(1, 0, 1))
));
// Create Testing Geometry
pCell->CreateFromGeometry(Tris);
// Load Sample Material
pCell->SetMaterial(0, m_pMaterial);
// Finalization
pCell->Finalize();
// Set the root component
// RootComponent = (UVFProceduralMeshComponent*)pCell->m_pProducealMesh;
};
Now VFMesh is a rather simple class:
UCLASS()
class ... UVFMesh : public USceneComponent
…
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// >> Constructor
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UVFMesh::UVFMesh()
{
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// >> Initialize
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void UVFMesh::Create()
{
// Create produceal mesh generator
m_pProducealMesh = ConstructObject<UVFProceduralMeshComponent>(UVFProceduralMeshComponent::StaticClass(), this, "VFMesh");
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// >> Load from geometry
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
bool UVFMesh::CreateFromGeometry(const TArray<FProceduralMeshTriangle>& vTriangles)
{
// Clear the previous buffer
m_pProducealMesh->ClearProceduralMeshTriangles();
// Set the new triangles
return m_pProducealMesh->SetProceduralMeshTriangles(vTriangles);
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// >> Set the material
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void UVFMesh::SetMaterial(int iElementIndex, UMaterialInterface *p)
{
m_pProducealMesh->SetMaterial(iElementIndex, p);
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// >> Finalize mesh
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void UVFMesh::Finalize()
{
// Make sure the world exists
check(GetWorld())
m_pProducealMesh->AttachTo(this);
m_pProducealMesh->RegisterComponent();
m_pProducealMesh->SetWorldLocation(FVector(0, 0, 0));
m_pProducealMesh->SetWorldRotation(FQuat(0, 0, 0, 1));
}
The m_pProducealMesh is a class gathered from:
Now I debugged through and everything works out fine, and the engine seems to register the component fine ( Meaning no errors nor warnings ). Although there is simply no trace inside the editor that the new custom mesh is being rendered, and I have no clue why.
And why is it that everything is a child to the billboard? The billboard is created as following inside VFTerrain, could it be because as the billboard is set to dissapear ingame all children dissapear too?:
m_pBillboard = ObjectInit.CreateEditorOnlyDefaultSubobject<UBillboardComponent>(this, TEXT("VFTerrain_BillBoard"));
Thank you for your time.