In UE5, I can use CreateDefaultSubobject to create a subobject within the constructor of…
- User
In UE5, I can use CreateDefaultSubobject to create a subobject within the constructor of e.g. an actor. But, how do I create an object later, for example in PreInitializeComponents?
Assistant
To create an object in PreInitializeComponents, you can use the
NewObjectfunction instead ofCreateDefaultSubobject.Here's an example of how you can use
NewObjectto create an instance of a custom class in PreInitializeComponents:[RequireComponent(typeof(MyCustomClass))] public class MyActor : Actor { private MyCustomClass _myCustomClassInstance; protected override void PreInitializeComponents() { base.PreInitializeComponents(); _myCustomClassInstance = NewObject<MyCustomClass>(); // Use _myCustomClassInstance here } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.