When interacting with blueprints though C++, you can modify the C++ members through UPROPERTY
s to your heart’s content, but when it comes to UFUNCTION
s, the inputs need to remain const
. Why is that?
I have a situation where I want UMG to launch a rocket to another planet when I hit a button, and have the rocket class internally track the destination until it arrives:
UFUNCTION(BlueprintCallable, Category = "Mechanics")
virtual void launch(AActor* &destination);
AActor* &destination
would need to be non-const, because the member I’m assigning that destination to will repeatedly change as the rocket goes from planet to planet. Unfortunately, even though the return
is void
, it still sets up &destination
as an output in the blueprint.
I also have a function that should allow UMG to set the rocket’s location based on actor and offset from the actor:
UFUNCTION(BlueprintCallable, Category = "Mechanics")
virtual void setLandedLocation(AActor* &body, const FVector offset = FVector(0, 0, 0));
The parameter AActor* &body
also needs to be non-const, because the body will eventually change when the rocket goes from planet to planet.
Abstracting away members and variables is nice way to keep classes bug-free, so I’m slightly confused as to why OOP getters and setters are not allowed in UFUNCTIONS.
Am I missing something here?
Thank you,
BeariksonStudios