Try to create sphere at runtime

i found this in the api section math : FSphere | Unreal Engine Documentation
how i can use at or get the triangles so i can render at (build a method do that thu A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums)

basically my question how i can make a sphere

I can’t help you with procedural mesh generation, but I can tell you that the FSphere type is merely the mathematical representation of a sphere, i.e. a center point plus a radius. Beyond that it holds no geometry information, such as a triangulation into polygons.

That being said, you can use an FSphere instance as the basis for creating your own spherical meshes. There are many ways to triangulate a sphere, and I’m pretty sure we already have code for that. Perhaps take a look at the BSP code for sphere brushes until someone else can provide a better answer :slight_smile:

#PrimitiveDrawingUtils.CPP

has the sphere drawing algorithms that you want, literally creating a DynamicMesh

:slight_smile:

DrawSphere (Mesh, not wireframe, actual triangles)

void DrawSphere(FPrimitiveDrawInterface* PDI,const FVector& Center,const FVector& Radii,int32 NumSides,int32 NumRings,const FMaterialRenderProxy* MaterialRenderProxy,uint8 DepthPriority,bool bDisableBackfaceCulling)
{
//see the .cpp for the rest for legal reasons

I don’t find any of this in the documentation. In fact, FSphere is not a graphical representation. And PrimitiveDrawingUtils is not mentioned in the docs. Not very easy how to do this when you are a beginner, really…

watch this. How To Do Line Tracing Using C++ In Unreal Engine - YouTube

Update for UE5.3 or later versions:

If you want to dynamically generate a solid sphere mesh inside the render thread, particularly within the FPrimitiveSceneProxy::GetDynamicMeshElement function, use this function:

void GetSphereMesh(const FVector& Center, const FVector& Radii, int32 NumSides, int32 NumRings, const FMaterialRenderProxy* MaterialRenderProxy, uint8 DepthPriority,
    bool bDisableBackfaceCulling, int32 ViewIndex, FMeshElementCollector& Collector, bool bUseSelectionOutline, HHitProxy* HitProxy)

This function is defined in PrimitiveDrawingUtils.cpp.

To see example code related to GetSphereMesh(..), refer to FDebugRenderSceneProxy::FSphere::Draw(..). This can be found in DebugRenderSceneProxy.cpp.

There is also a function called DrawSphere in the same file, but if you want to save time, do not use it. When attempting to call DrawSphere inside GetDynamicMeshElement, it will throw a nullptr exception at the following line :frowning:

// here, PDI->View is nullptr when you try to call DrawSphere(..) within GetDynamicMeshElement(..)
FDynamicMeshBuilder MeshBuilder(PDI->View->GetFeatureLevel());