Hi, I want to Create a pure function in C++ how to do it?
What I am trying is :
void [[gnu::pure]] GetWeight();
please correct me if I am wrong.
Hi, I want to Create a pure function in C++ how to do it?
What I am trying is :
void [[gnu::pure]] GetWeight();
please correct me if I am wrong.
UFUNCTION(BlueprintCallable, BlueprintPure)
float myFloatSum(float A, float B);
This will make the function expose to blueprints as a pure function but it will still remain impure on C++ side.
Please correct me if I am wrong.
What is a pure function in C++ for you?
Because definition of a Pure function in code is a function where you give same parameters and get same results ( sin(), sqrt(). flor() ) and impure is one that return different values (random(), time() )
#Pure
UFUNCTION(BlueprintCallable, BlueprintPure)
int foo(int n)
{
return n*2;
}
#Impure
int i = 42;
UFUNCTION(BlueprintCallable)
int bar(int n)
{
++i;
return n*i;
}
I thought its something need to pure on C++ side too, and the UPROPERTY is only making it pure on bp side, but now its all cleared I have no doubts anymore on this theory, Thank You for help to learn this.
Thank You for this example and It makes the eldany.uy example more clear to understand. Thank You so much.
I think the definition of Pure in Blueprints is not right because you can make a pure BP function with time, random, modify external variables, whatever inside (impure function) and Unreal accepts it as pure anyway.
Pure definition for BPs is more like a function with no execution pin, but you can actually change everything inside the function anyway.
In C++ pure or impure is a concept on how do you make the function only exactly like the example of @c0r37py
anyway his example is like this:
UPROPERTY(BlueprintReadWrite)
int i = 42;
UFUNCTION(BlueprintCallable, BlueprintPure)
int bar(int n)
{
i++;
return n*i;
}
so in theory IMPURE function but it works perfectly and can use as ‘pure’ in blueprints without
any error.