UnrealScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a circle"
// Create a circle in Unreal UStaticMeshComponent* ACircleActor::CreateCircle(float Radius, int32 NumSides) { UStaticMeshComponent* CircleMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Circle Mesh Component")); CircleMesh->SetupAttachment(RootComponent); TArray<FVector> Vertices; float AngleStep = 360.0f / NumSides; for (int32 i = 0; i < NumSides; i++) { float Angle = i * AngleStep; FVector Vertex = FVector(FMath::Cos(FMath::DegreesToRadians(Angle)) * Radius, FMath::Sin(FMath::DegreesToRadians(Angle)) * Radius, 0.0f); Vertices.Add(Vertex); } // Create a procedural mesh and set its vertices UProceduralMeshComponent* ProceduralMesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("Procedural Mesh Component")); ProceduralMesh->SetupAttachment(CircleMesh); ProceduralMesh->CreateMeshSection(0, Vertices, TArray<int32>(), TArray<FVector>(), TArray<FVector2D>(), TArray<FColor>(), TArray<FProcMeshTangent>(), true); return CircleMesh; }