I have a function that should take two arguments and return the other two (different types). How can I return them so that I can use them in other C++ functions?
Make a return type of TTuple<var1,var2,ā¦>
Where vars can any exposed unreal variable types
for example
TTuple<float,bool> AMyCharacter::DoSomething()
{
float myfloat_value = 1.0f;
bool mybool_value = false;
return MakeTuple(myfloat_value,mybool_value);
}
Thank you so much!!!
A more ātraditionalā way of doing that is using a regular return value, and an Out param, although frankly, for exactly two values, I feel like using a Tuple is far more readable with the intent.
bool AMyCharacter::DoSomething(float& OutFloat)
{
OutFloat = 1.0f;
return false;
}
Youāll see that pattern all over Unreal, bringing it up so you recognize it. IMO the Tuple is much cleaner, though. Some might argue that creating a new data structure is unnecessary, so donāt, though. But unless itās a critical performance area, Iād go with the Tuple.
[Error]Unrecognized type āTTupleā - type must be a UCLASS, USTRUCT or UENUM
Why I Cant UFUNCTION?
UFUNCTION(BlueprintCallable)
TTuple<bool, int32> AddToInvenoty(FName ItemID, int Quantity);
TTuple is not exposed to blueprints
.h
USTRUCT(Blueprintable)
struct FInventorytStruct
{
GENERATED_BODY();
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
bool Added;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
int32 index;
};
UFUNCTION(BlueprintCallable)
void AddToInvenoty(FName ItemID, int Quantity, FInventorytStruct& outValue);
.cpp
void AMyCharacter::AddToInvenoty(FName ItemID, int Quantity, FInventorytStruct& outValue) {
outValue.Added = true;
outValue.index = 22;
}
(after right clicking spit struct for output)
And how i can use this is struct on my cpp funcs
Either put it in a separate header and include it or put it at the top of your header file if itās just used with 1 class (has to be above the uclass definition)
I mean how to use the value that the function will return if I pass it to &FStructName?
inside the function when you set the properties of the struct, they will be returned by reference.
Use these return values.
Thank you very much, I just realized that Iām very stupid
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.