# Controlling Particle Effects from Code

Hi,

I’m trying to come up with a way to use a Particle Beam to define the orbit of a planet. (Multiple planets and moons actually)

Being inexperienced with particles, I followed this tutorial: Intro to Cascade: Creating a Beam Emitter | 07 | v4.2 Tutorial Series | Unreal Engine - YouTube

I already have a function which takes Keplerian elements & game clock data, and converts that information into a Cartesian Vector at the angle the True Anomaly. This is just a “Static FVector”

However, one thing I would like to do is run a static function which can return a vector array of points - let’s say 360 - one for each degree - and then finding a way to point each segment of the Orbit Particle such that Source = FVector(n), Target = FVector(n+1)

**Q. ** Now - the first big question - should I use just one “long” particle and use the interpolation points - or should I try to spawn 360 particles and point them one vector to the next?

Also - is it possible to create a static TArray for vectors? I’m having problems getting it to compile. I tried a few different methods, including loading an array into a struct.

Struct Defined - this works fine

``````
//DEFINE STRUCT FOR ALL KEPLERIAN ELEMENTS
USTRUCT(BlueprintType)
struct FavKepArray
{
GENERATED_USTRUCT_BODY()

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Trajectory Array")
TArray<FVector> KepPoints; //Cartesian Vector
//UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Trajectory Array")
//float MApt; //Mean Anomoly
};

``````

``````
//FavKepArray
UFUNCTION(BlueprintCallable, Blueprintpure, Category = "Astrodynamics")
static FavKepArray avFgetOrbitPoints(FVector ParentLocation, float ParentMass, float BodyMass, float A, float Ec, float I, float O, float W, float Epoch, float GameScale, float GameSpeed, float ArrayDefinition);

``````

Code Body
Here’s where the problems start - I’m still too novice to know how member functions really work - so I don’t know if a member function can be a static array - or if can be a user defined Ustruct. I’m not even sure how best to access the member objects of a struct in this case.

``````
FavKepArray UavFindCartesian::avFgetOrbitPoints(FVector ParentLocation, float ParentMass, float BodyMass, float A, float Ec, float I, float O, float W, float Epoch, float GameScale, float GameSpeed, float ArrayDefinition)
{

//DEFINE THE ARRAY WHICH WILL BE RETURNED
//TArray <FVector> OrbVectorArray;
FavKepArray OrbVectorStruct;
//.KepPoints];

//OrbVectorStruct

//OrbVectorArray = OrbVectorStruct.KepPoints;

//GAME STARTING EPOCH
double startingEpoch = 2460676.5; // For Jan 1 2025
double coordEpoch = 2451696.5; //For Jan 1 2000 - "Epoch 2000"

//CONVERT SEMI-MAJOR AXIS INTO M
float Am = A * 149597870691.0134;

float Irad = I * PI / 180.f; //Inclination
float Orad = O * PI / 180.f; //Omega - long of Ascending Node
float Wrad = W * PI / 180.f; //Argument of Perihelion

//float MArad = 180.0f * PI / 180.f; //MEAN ANOMOLY TOTAL

for (int i = 0; i < ArrayDefinition - 1; i += 1) {

//CALC TRUE ANOMOLY Over 360 * for N points defined by ArrayDefinition
float TA = (360.0f / ArrayDefinition) * PI / 180.f;

double R = Am * (1.0f - Ec * Ec) / (1.0f + Ec * cos(TA)) * GameScale; // *GameState->PixelsPerAU;

//BORROW CALCS FROM TIME DEP. FUNCTION
float Za = R * sin(TA + Wrad) * sin(Irad) / 149597870691.0134;

}

return OrbVectorArray;
}

``````

Anyway, the plan was to use a static function to get a Vector Array - and then to return that to a Blueprint where I might combine it with a “Add Particle System” Node - something like this:

Any advice for manipulating the shape of a particle beam, and/or how to deal with static arrays - would be greatly appreciated!
Cheers

Just had a thought, is there any way to control a particle emitter path by creating a custom Particle Module?

IE:

UCLASS()
class AV_API UavKeplerLine : public UParticleModule

Or maybe I want to Override the “Target” Module. Any examples linking particles with vector arrays would be nice I figured out how to do this with blueprints (mostly)

Followed direction on here, but didn’t need to use Splines: 