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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

NewObject or CreateDefaultSubobject

Hi all,

I'd like to know what is the difference between the 2 methods stated in the title.


 USphereComponent* Component = NewObject<USphereComponent>(this);
 USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent"));

Thank you.

Product Version: UE 4.9
more ▼

asked Oct 12 '15 at 08:12 PM in C++ Programming

avatar image

86 3 4 9

avatar image Katianie Nov 11 '15 at 03:25 AM
  • you read my mind.

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

3 answers: sort voted first

CreateDefaultSubobject in constructor (you need to decler component in constructor in order to see them in extended blueprint, other wise you creating component dynamicly), NewObject everywhere else

more ▼

answered Oct 12 '15 at 08:29 PM

avatar image

36.6k 931 169 1111

avatar image wiwip Oct 14 '15 at 01:16 AM

That simple!

Thank you.

avatar image Shadowriver Nov 11 '15 at 05:06 AM

I use the fact Katianie posted comment to extend the anwser. I never investigate that but my guess is CreateDefaultSubobject is designed to spawn component, because content of constructor is exclusivly used in Class Default Object (CDO) which could not have secundery objects spawned, CreateDefaultSubobject don't spawn object but leaves information to create component object on spawn.

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

From what I understand, NewObject creates and instance that is not visible to editor however instance created by CreateDefaultSubobject is visible to editor. For example, if you create instance of camera using CreateDefaultSubobject and attach it to your pawn, then that camera will actually appear as child of pawn in editor. This is also why CreateDefaultSubobject usage is restricted to constructor.

more ▼

answered Sep 25 '17 at 04:06 AM

avatar image

246 16 31 47

avatar image darkgaze Mar 08 '18 at 07:57 PM

But it is not editable and also you can't modify some stuff on them. They appear as Inherited components... a little hidden there. Sometimes they don't come up unless it's the rootComponent... (4.18)

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

if we want create something dynamically or in other word creating in Run-time we are using newobject but createdefaultsubject it is not for creating something dynamically we create it once.

more ▼

answered Nov 19 '18 at 08:31 AM

avatar image

1 1

(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