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"

'Nested' Includes between a custom pawn and a custom component

I'm trying to set up a UActorComponent for a custom pawn. This custom pawn, however, would also like a reference to its owner - which will always be the custom pawn.

Accordingly in my CustomPawn.h, I #include "CustomComponent.h" to make the custom component a variable, UCustomComponent* CustomComponent.

However, in CustomComponent.h, in order to have a ACustomPawn* MyOwner, I need to #include "CustomPawn.h"

This results in compiling errors, specifically an error C2143: syntax error: missing ';' before '*' on my UCustomComponent* CustomComponent line. I understand that it has to do with two headers including eachother; however, all I'm getting is that I need to use #ifndef #define, unless I have #pragma once, which UE4 by default uses.

What do you all suggest?

Product Version: UE 4.10
Tags:
more ▼

asked Feb 06 '16 at 05:14 PM in C++ Programming

avatar image

Kowbell
165 20 29 39

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

1 answer: sort voted first

Hi Kowbell!

You can access component's owner by GetOwner() method. It will return direct parent of component, I mean if component is attached to another component then GetOwner() will return that parent component. But in your case I think component is parented by actor itself, so you can use GetOwner() instead storing MyOwner property.

If you want to avoid recursive including, then you can use forward class declaration. Eg:

CustomPawn.h:

 class UCustomComponent* CustomComponent;

CustomPawn.cpp:

 #include "CustomComponent.h"
 
 CustomPawn::CustomPawn()
 {
   CustomComponent = ...
 }


more ▼

answered Feb 06 '16 at 06:58 PM

avatar image

alkohol
236 12 5 16

avatar image alkohol Feb 06 '16 at 07:01 PM

You can find similar examples in default projects templates (and in many other places)

avatar image Kowbell Feb 06 '16 at 07:35 PM

I was hoping to store my owner as the custom pawn class because in several different parts of the program I wanted to reference variables specific to that class, and casting to that class every time via GetOwner() would get very tedious. Out right now, I'll try that out when I get back.

Edit: That worked! Thanks!

(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