Hi.
In my c++ class, I have written this simple function:
TArray ABuilder::CreaGliglia(int32 MaxRighe, int32 MaxColonne, float MaxDistanzaTraRighe, float MaxDistanzaTraColonne)
{
TArray<FVector> Array;
FVector Posizione;
USceneComponent* Scene = GetRootComponent();
if (Scene)
{
float Xpos = Scene->GetComponentLocation().X;
float Ypos = Scene->GetComponentLocation().Y;
for (int32 i = 0; i != MaxRighe; i++)
{
float X = i * MaxDistanzaTraRighe;
for (int32 a = 0; a != MaxColonne; a++)
{
float Y = a * MaxDistanzaTraColonne;
Posizione.Set(Xpos + X, Y + Ypos, 0.f);
Array.Add(Posizione);
}
}
}
return Array;
}
The function works.
Then I have created a second function which i want to call In Blueprint exposed like this:
UFUNCTION(BlueprintCallable, Category = “Builder Function”)
TArray CreaGligliaInBp();
And in cpp it looks like this:
TArray ABuilder::CreaGligliaInBp()
{
TArray Matrix = CreaGliglia(GetRighe(), GetColonne(), GetDistanzaTraRighe(), GetDistanzaTraColonne() );
return TArray<FVector>();
}
where GetRighe(), GetColonne() (Basically getrows() and getColumn() and so on) are just getter methods (or function): they returns the value of the variable passed as parameter to the function.
Righe (rows) and Colonne (column) are exposed like this:
UPROPERTY(EditAnywhere, Category = “Construction”)
int32 Righe;
/*numero di colonne*/
UPROPERTY(EditAnywhere, Category = "Construction")
int32 Colonne;
Now, if I call the function named CreaGligliaInBp() and tie the (returned) array in a lenght node and print string I get 0 value: even if I change the values of righe (ows) and colonne (column)
Basically here lies the mistake, in the second funcion:
TArray Matrix = CreaGliglia(GetRighe(), GetColonne(), GetDistanzaTraRighe(), GetDistanzaTraColonne() );
the getter methods doesn’t return the variable’s value exposed in Bp.
So the question is: How can I call a function in C++ using the variable exposed in bp?
I know I could override the function in the Bp child and if I use the getter method the trick works.
But I am interested in learning how I can run a c++ function whose variables are esposed in Bp.
Thanks in advance