Spawn on a sphere

Hey all,

Here is an interesting one:

I’m in search of a blueprint that would let me spawn objects on a sphere, something like this:
image

either an unreal sphere, an FBX sphere, using vertex positions,
or no actual spere at all just calculations.

Is that possible?

The location and rotation should be calculated so the objects are pointing outwards.

Thanks a lot!

Pick a random unit vector; Spawn thing with location = SphereCenter + RandomVector*SphereRadius, the rotation can be set from the same RandomVector, add extra constant rotation if it isnt enough.

If you need to pick point from mouse, then something like ConvertMouseLocationToWorldSpace, but then you isn’t limited to sphere

Would that result in a consistent placing? I’m looking actually for the opposite of random,
more like accurate placing on the vertex,

image

Is that possible?

Thanks a lot

The principal is still the same, just pick the vector somehow meaningfully.

Not 100% sure i wrote the math correctly, but something along those lines should work

float VerticalStep = 10;
float HorizontalStep = 20;
float Radius = 1234;
for(float i = 0; i < 180; i+=VerticalStep)
    for(float j = 0; j <= 360; i+=HorizontalStep)
    {
       FVector Dir = FVector::UpVector;
       Dir = Dir.RotateAngleAxis(i, FVector(0,1,0));
       Dir = Dir.RotateAngleAxis(j, FVector(0,0,1));
       DrawMyObject(Center, Radius, Dir);
    }

Maybe HorizontalStep should also depends on VerticalStep instead of being independed constant value

I’m not so great with coding, so I’m using Blueprints only, therefore I’m not so sure how to Blueprint this code.

update! found this tutorial, will have time tomorrow to try it out:

Also !
Found out about this:

The Procedural Content Generation Framework (PCG)

But this scheme is just a random sketch that does nothing, I have no clue how to get it into actual points in a regular blueprint, this is a special one:
image

Getting the mesh from a blueprint is quite the tricky task using this PCG system, but here is how you do it!

First make sure you have the PCG Geometry Script plugin enabled. Then you want to go to your blueprint and add the PCG graph as a component.

In your PCG graph, you need the Get Actor Property node. This lets you look for certain components inside the actor. Your Actor Filter should be set to self because self would be the blueprint you’ve added the PCG component to. Property Name should be the name of your mesh inside the blueprint. In my case its “StaticMeshRef” then you need to output this attribute name to feed into the Mesh Sampler so it knows which mesh to sample. The sampling method and seed can of course be whatever you want. Then you need to get actor data and copy those points, now it should place points on your mesh when its in the world without a PCG volume.
(Ignore the scale inheritance, that’s not relevant for this)

Hope this helps!

Due to it only being my first post I can only put one image in the reply.