Hey I’m trying to get into procedural generation and ran into the following problem. I made a base class in c++ with a few UProperties to create a basic quad.
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class PROCEDURALTERRAIN_API UTerrainGeneratorComponent : public UActorComponent
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FVector GridOffset;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float CellSize;
private:
class UProceduralMeshComponent* Mesh;
protected:
UFUNCTION(BlueprintCallable)
void GenerateGrid(FVector IGridOffset, float ICellSize);
....
};
The GenerateGrid function just creates a quad at the moment.
void UTerrainGeneratorComponent::GenerateGrid(FVector IGridOffset, float ICellSize)
{
TArray<FVector> Vertices;
TArray<int32> Triangles;
TArray<FVector> Normals;
TArray<FVector2D> UV0;
TArray<FColor> VertexColors;
TArray<FProcMeshTangent> Tangents;
if (const AActor* Owner = GetOwner())
{
float VertexOffset = ICellSize * 0.5f;
Vertices.Add(FVector(-VertexOffset, -VertexOffset, 0.f) + IGridOffset + Owner->GetActorLocation());
Vertices.Add(FVector(-VertexOffset, VertexOffset, 0.f) + IGridOffset + Owner->GetActorLocation());
Vertices.Add(FVector(VertexOffset, -VertexOffset, 0.f) + IGridOffset + Owner->GetActorLocation());
Vertices.Add(FVector(VertexOffset, VertexOffset, 0.f) + IGridOffset + Owner->GetActorLocation());
Triangles.Add(0);
Triangles.Add(1);
Triangles.Add(2);
Triangles.Add(2);
Triangles.Add(1);
Triangles.Add(3);
Mesh->CreateMeshSection(1, Vertices, Triangles, Normals, UV0, VertexColors, Tangents, true);
UE_LOG(LogTemp, Warning, TEXT("[Terrain Generator]: Offset: %s"), *IGridOffset.ToString());
}
}
I then made a blueprint based on an Actor and added the Component to it. The GenerateGrid function gets called in the ConstructionScript and in the event Graph with a custom event with Call in Editor set to true.
The problem now is that changes made to the uproperties in the editor only work when called through the custom event. In the construction script the values are always 0 and therefore nothing visible is generated. Is this some kind of bug or am I doing something wrong?