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"

Owner claimed to be "AActor" when it should not be

When trying to get reference (pointer, actually) to parent/owner:

 APlayer_Obj* PlayerCharacter = GetOwner();

I get this error:

 a value of type "AActor *" cannot be used to initialize an entity of type "APlayer_Obj"


I have set the owner/parent in the class to be "APlayer_Obj" like this:

 class TESTGAME_API APlayerChildClass : public APlayer_Obj

Yet it treats the "GetOwner()" as if APlayerChildClass is directly the child of Actor, to my understanding. Why is it doing this? I need to get a reference of the actual parent/owner that I've set, how can I do this?

Product Version: UE 4.20
Tags:
more ▼

asked Feb 09 '19 at 04:58 PM in C++ Programming

avatar image

L11777
6 1 2 4

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Try casting it this way:

 APlayer_Obj* PlayerCharacter = Cast<APlayer_Obj>(GetOwner());

Just make sure you check that GetOwner() is valid (not null).

more ▼

answered Feb 09 '19 at 05:41 PM

avatar image

Chyros
1.2k 8 4 7

avatar image L11777 Feb 11 '19 at 03:08 PM

Interesting, but why would owner be AActor by default and not APlayer_Obj as I've set it? Or do I not understand something about parenting correctly? Putting "APlayer_Obj" at the end of this line would make it the owner, no?

 class TESTGAME_API APlayerChildClass : public APlayer_Obj
avatar image Chyros Feb 11 '19 at 03:58 PM

Because GetOwner() was declared as AActor in Actor.h (see below):

 /**
  * Get the owner of this Actor, used primarily for network replication.
  * @return Actor that owns this Actor
  */
 UFUNCTION(BlueprintCallable, Category=Actor)
 AActor* GetOwner() const;



avatar image L11777 Feb 11 '19 at 08:54 PM

That just makes things a bit more confusing. Is the parent/owner class changed to the class that I define in the line I mentioned before? Is parenting different for classes and actual object instances that are being created? Because my main point here is to have this code be child of the player class in some form and have it be able to reference the player object so it can apply changes to the player object.

avatar image Chyros Feb 12 '19 at 05:33 AM

It's hard for me to explain without looking at your APlayer_Obj's .H file. I'm guessing your APlayer_Obj's parent class is AActor and it inherits the GetOwner() function of AActor? So by default GetOwner() is AActor until you cast it to a specific class that has a base parent of AActor.

(comments are locked)
10|2000 characters needed characters left
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