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"

UE4 Actor constructor

So i Wanted an actor class to contain another actor , so i have 2 actors one called Aapples and ATree.

Aapples is just a actor generated code by editor.

Atree code here it is :

 #include "apple.h"
 #include "GameFramework/Actor.h"
 #include "Tree.generated.h"
 class ATree : public AActor
     Aapple apples[100]

this generates this error : `Error 1 error : In Tree: Missing '*' in Expected a pointer type

So i replaced it with pointers to object so later i can initalize them in my code so i changed it to : Aapple* apples[100]

But i dont know how to initalize apples in the code i tried this in Tree.cpp : in middle of code: apple[0] = new Aapple();

ofcourse there is no constructor with this arguments as all actor constructors are like this :

   Aapple::Aapple(const class FPostConstructInitializeProperties& PCIP)
         : Super(PCIP)

So i tried this apples[0]= new Aapple(PCIP); but PCIP is not defiend , so how do i initalize an acotr class ?

Product Version: Not Selected
more ▼

asked Aug 15 '14 at 09:35 PM in C++ Programming

avatar image

112 22 21 29

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

1 answer: sort voted first
 apples[0] = GetWorld()->SpawnActor<AApple>(AApple::StaticClass());

Also, make sue you call that in BeginPlay() and not the constructor, because the world will not be valid in the constructor and crash.

more ▼

answered Aug 22 '14 at 01:43 PM

avatar image

James Ordner
382 16 17 25

avatar image TheTrice Aug 25 '14 at 03:38 AM

Thanks!! James

(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