x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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???
  }

Product Version: UE 4.21
Tags:
more ▼

asked Feb 06 '19 at 09:10 AM in C++ Programming

avatar image

TooDear
55 2 6 9

avatar image HarryHighDef Feb 06 '19 at 09:24 AM

Return is as a pointer.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

more ▼

answered Feb 06 '19 at 09:41 AM

avatar image

carpet200
93 3 4 7

avatar image TooDear Feb 06 '19 at 10:15 AM

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! :D TNXXXXX

avatar image Shadowriver Feb 06 '19 at 10:32 AM

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

avatar image TooDear Feb 06 '19 at 11:31 AM
  int *X; 

is same as

  int* X; ???

But proper way is to declare pointer type as:

  int* X; 

cuz pointer is type? right?

avatar image TooDear Feb 06 '19 at 11:37 AM

Can you explain why

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

works, but

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

does not??? Tnx

avatar image carpet200 Feb 06 '19 at 12:03 PM
 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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question