I’m unable to get this work in the current version of the engine. I’ve created a c++ function library
#pragma once
#include "Engine.h"
#include "Components/StaticMeshComponent.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "StaticMeshResources.h"
#include "kohLibrary.generated.h"
/**
*
*/
UCLASS()
class TEST_API UkohLibrary : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()
UFUNCTION(BlueprintPure, Category = "KohFunctions", meta = (Keywords = "vertex mesh get", NativeBreakFunc))
TArray<FVector> MeshData(const UStaticMeshComponent* StaticMeshComponent);
};
#include "Test.h"#include "kohLibrary.h"
#include "Components/StaticMeshComponent.h"
#include "StaticMeshResources.h"
UkohLibrary::UkohLibrary(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
TArray<FVector> UkohLibrary::MeshData(const UStaticMeshComponent* StaticMeshComponent)
{
TArray<FVector> vertices = TArray<FVector>();
//~~~~~~~~~~~~~~~~~~~~
// Many thanks to for this solution! :)
//
// Vertex Buffer
if (!IsValidLowLevel()) return vertices;
if (!StaticMeshComponent) return vertices;
if (!StaticMeshComponent->StaticMesh) return vertices;
if (!StaticMeshComponent->StaticMesh->RenderData) return vertices;
if (StaticMeshComponent->StaticMesh->RenderData->LODResources.Num() > 0)
{
FPositionVertexBuffer* VertexBuffer = &StaticMeshComponent->StaticMesh->RenderData->LODResources[0].PositionVertexBuffer;
if (VertexBuffer)
{
const int32 VertexCount = VertexBuffer->GetNumVertices();
for (int32 Index = 0; Index < VertexCount; Index++)
{
//This is in the Static Mesh Actor Class, so it is location and tranform of the SMActor
const FVector WorldSpaceVertexLocation = GetActorLocation() + GetTransform().TransformVector(VertexBuffer->VertexPosition(Index));
//add to output FVector array
vertices.Add(WorldSpaceVertexLocation);
}
}
}
return vertices;
}
The errors are located in the red line. What is wrong?