AActor as a return type. How to do this? PLS!

I want my function to return actor pointed by *pointer… I tried but I can’t figure it out. Pls help me…

newfile.h

 #include "GameFramework/Actor.h"


 UFUNCTION(BlueprintCallable, meta = (DisplayName = "funkcija"))
      AActor rFunc(AActor *pointer);

newfile.cpp

 #include "GameFramework/Actor.h"

 AActor newfile::rFunc(AActor *pointer)
 {
      return *pointer;     //Won't work, how do I do this
 }

your return type for the function needs to be AActor* instead of AActor.

AActor* newfile::rFunc(AActor* pointer)
{
return pointer;
}

But why do you want to return a pointer if you used it as argument? You already have the pointer

Return is as a pointer.

asterisk at *pointer might misguide you. Pointer is a type and you mark it with asterisk after the type name so AActor*.

THANK YOU!!! You are GOD!!
I want my func to do other staff but return on which actor that staff was done…
Ufff… Im a total rookie here, u have no idea how much u saved my brain from annihilation! :smiley: TNXXXXX

int *X;
is same as

 int* X; 

But proper way is to declare pointer type as:

 int* X; 

cuz pointer is type? right?

Can you explain why

 AActor* newfile::rFunc(AActor* pointer) { return pointer; }

works, but

 AActor newfile::rFunc(AActor *pointer)
 {
  return *pointer; 
  }

does not Tnx

int X;
//is the same as
int
X;
The * applies to the variable type, therefore the most logical syntax to use is the one at the bottom.

And to answer the second question, the reason for this not working:

AActor newfile::rFunc(AActor *pointer)
  {
   return *pointer; 
  }

This would work if you used int for example, but unreal have protected it’s classes from misuse (i guess).
What you do in this function is the following:

  1. Inputs an AActor* variable (a pointer) as argument
  2. Dereferences that pointer variable and returns it as a Non-pointer. Meaning, you return the actual AActor not the pointer