Pointer to the USTRUCT

Hi there. So I have two custom USTRUCT’s, and a C++ function which I want to call in Blueprint:

USTRUCT(BlueprintType)
struct FProjectileParams
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	FVector StartLocation;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	FRotator StartRotation;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float Velocity;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float RotationSpeed;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	FRotator DesiredRotation;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float WaitTime = 0.f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float LauncherRotationSpeedYaw;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float LauncherRotationSpeedPitch;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	UStaticMesh* Mesh;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float SizeK = 1.f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float FuelTank = 1.f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float FuelExpense = 0.f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	bool isBallistic;
};

USTRUCT(BlueprintType)
struct FTargetParams
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	FVector StartLocation;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	FRotator StartRotation;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float Velocity;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float RotationSpeed;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	TArray<FVector> Path = {};

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	UStaticMesh* Mesh;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float SizeK = 1.f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float FuelTank = 1.f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	float FuelExpense = 0.f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Initialize")
	bool isBallistic;
};

In this function I first take some values from those structures and then write down some other values into ProjectileParams, that’s why I use &

UFUNCTION(BlueprintPure, meta = (Step = 0.1))
bool ParabolaParabola3D(FProjectileParams& ProjectileParams, FTargetParams& TargetParams, float Step, float& CollisionTime);

But when I call this function in Blueprints, this is what it looks like:


So the question is how do I make it look not that ugly? How do I avoid those two “Set” nodes? Maybe some other function which will take the results and then just manually write down all the information? Please help.

perhaps passing in by reference?

UFUNCTION(BlueprintPure, meta = (Step = 0.1))
bool ParabolaParabola3D(UPARAM(ref) FProjectileParams& ProjectileParams, UPARAM(ref) FTargetParams& TargetParams, float Step, float& CollisionTime);

byref

That way you modify the structs you pass in and then they remain changed after the function executes.

No setter needed.

It couldn’t work better, thanks for your help. Before I didn’t even know UPARAM() was a thing, and now my inner perfictionist can lihe a happy life.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.