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"

C++ Tanks vs Zombies 01: UProperty()...class? CreateDefaultSubject?

Hi, this tutorial series seems to be very nice! Looking forward to see more c++, although i'm already stuck in the first video of this series now :) There are two things I don't understand, and i don't wanna progress until i do understand these (propably) very basics:

  • In the tank.h header file we got these UPROPERTIES:

       UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Tank", meta = (AllowPrivateAccess = "true"))
     UArrowComponent* TankDirection;
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Tank", meta = (AllowPrivateAccess = "true"))
     class UPaperSpriteComponent* TankSprite;

The first looks normal to me - just a pointer to an UArrowComponent, but why is there a "class" tag on the second one? (I'm new to c++, guess it's basic c++ coding, but some explanation would be nice about that)

  • The other thing is this CreateDefaultSubobject Methods in the tank.cpp. Haven't found too much info about that on web. Is this just the proper way to create Objects/Instances of UE4 Objects similar to new()?

Product Version: UE 4.16
more ▼

asked Jun 02 '17 at 07:23 AM in C++ Programming

avatar image

8 1 3

avatar image TrTintifax Jun 05 '17 at 08:26 AM

Thank you very much for the clarfication. This helped a lot!

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

2 answers: sort voted first

The class keyword is used in this context to forward declare the type. In c++ it's used to avoid including the file holding that class. This helps a lot when you are in situations with circular dependencies where you have two classes that need variables to eachothers.

The CreateDefaultSubobject functions create default components for your class. If I recall correctly then it may only be used in constructors and not in any othe functions. If you want to create an object that's not an actor during runtime then

 UObject *Object = NewObject<UObject>();

Is the way to go. Actors are a bit different as you need to spawn them in the world, thus need a reference to the world. An example is:

 UWorld *World = GetWorld();
 if (World)

Then you can enter a multitude of params based on your needs.


more ▼

answered Jun 02 '17 at 03:52 PM

avatar image

151 10 12 19

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

class means forward declaration and it is often used to avoid compile dependency in header file. CreateDefaultSubobject is used to create objects in the class constructor.

more ▼

answered Jun 02 '17 at 07:44 AM

avatar image

148 5 3 7

(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