Hello community!
I have been trying for days to properly define output parameters now. I am new to C++ and therefore I think I am just missing something very simple :D. This is my blueprint function, which I am now trying to rewrite in C++:
As you can see it has three input parameters and three output parameters.
Now this is the definition form my function in the .h file:
UFUNCTION(BlueprintCallable, Category = Utilities)
void GetClosestOverlappingActor(const UClass* ActorClassIN, const AActor* RelativeActorIN, const USphereComponent* CollisionComponentIN, class AActor* ClosestOverlappingActorOfTypeOUT, bool& IsAnyActorOverlappingOUT, UClass* ActorClassOUT);
This is the .cpp implementation:
void AActorUtilitiesCode::GetClosestOverlappingActor(const UClass* ActorClassIN, const AActor* RelativeActorIN, const USphereComponent* CollisionComponentIN, class AActor* ClosestOverlappingActorOfTypeOUT, bool& IsAnyActorOverlappingOUT, UClass* ActorClassOUT)
{
//Local varriables:
const AActor* LocalRelativeActor = RelativeActorIN;
float ClosestDistanceToActor = 0;
int32 ClosestActorIndex = 0;
// Get all overlapping actors
TArray<AActor*> OverlappingActors;
CollisionComponentIN->GetOverlappingActors(OverlappingActors, ActorClassIN->GetClass());
if (OverlappingActors.Num() > 0)
{
// If we have at least one appropriate actor then we have to find out which one is the closest
for (int32 iOverlapping = 0; iOverlapping < OverlappingActors.Num(); iOverlapping++)
{
// When we enter the forEach Loop, we set the very first actor here
if (ClosestDistanceToActor == 0)
{
// Sets thee actor index in for loop and sets the distance to the first element found.
ClosestActorIndex = iOverlapping;
ClosestDistanceToActor = RelativeActorIN->GetDistanceTo(OverlappingActors[iOverlapping]);
}
else
{
if (RelativeActorIN->GetDistanceTo(OverlappingActors[iOverlapping]) < ClosestDistanceToActor)
{
ClosestActorIndex = iOverlapping;
ClosestDistanceToActor = RelativeActorIN->GetDistanceTo(OverlappingActors[iOverlapping]);
}
}
}
ClosestOverlappingActorOfTypeOUT = OverlappingActors[ClosestActorIndex];
IsAnyActorOverlappingOUT = true;
UClass* ActorClassOutTemp = OverlappingActors[ClosestActorIndex]->GetClass();
ActorClassOUT = ActorClassOutTemp ->GetClass();
}
else
{
IsAnyActorOverlappingOUT = false;
}
}
Now the problem is when I am calling the function in BP the parameters “ActorClassOUT” and “ClosestOverlappingActorOfTypeOUT” are not output parameters. How can I achieve that? Here just for visualization the BP which I am calling:
Inside my code files the parameters are marked with “IN” and “OUT” to show you which ones I want to be in- and output.
BTW: I was thinking about a “Transport”-Struct to transport my parameters out of the function but that is just an idea and I believe there must be an easier way
Thanks in advance for your help!
Greets Linus