FObjectInitializer::CreateDefaultSubobject

Create a component or subobject

Windows
MacOS
Linux

Syntax

template<class TReturnType, class TClassToConstructByDefault>
TReturnType * CreateDefaultSubobject
(
    UObject * Outer,
    FName SubobjectName,
    bool bTransient
) const

Remarks

Create a component or subobject

Parameters

Parameter

Description

TReturnType

class of return type, all overrides must be of this type

TClassToConstructByDefault

class to construct by default

Outer

outer to construct the subobject in

SubobjectName

name of the new component

bTransient

true if the component is being assigned to a transient property

Example Code

MyStaticMeshActor.cpp at line 7:

AMyStaticMeshActor::AMyStaticMeshActor(const FObjectInitializer& ObjectInitializer)  
{  
    //Make our mesh component (named 'MyMesh') and set it up to be our root component  
    MyMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this,TEXT("MyMesh"));  
    RootComponent = MyMesh;  
}

References

Module

CoreUObject

Header

Runtime/CoreUObject/Public/UObject/UObjectGlobals.h

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback