Alternative to ConstructObject

Getting this warning:

ConstructObject is deprecated. Use
NewObject instead

However, I looked at the UObject Instance Creation docs and can’t find a proper substitute. I need to be able to pass in a name, parent (outer), flags, and most importantly a UClass of what I actually want to construct. NewNamedObject has most of these but lack the Class parameter–it does have a Template parameter but it crashes with the following message when I attempt to pass the class to it:

Assertion failed: !InTemplate ||
InTemplate->IsA(InClass) || (InFlags &
RF_ClassDefaultObject)

So how do I change this:

ConstructObject<UObject>(Class, Parent, Name, Flags);

To something else?

I think the following should work:

void AYourClass::OnConstruction(const FTransform &Transform)
{
	Super::OnConstruction(Transform);

	// Create and register Sprint Component
	YourObject = NewObject<UYourClassToSpawn>(this, UYourClassToSpawn::StaticClass(), TEXT("YourClassObjectName"));
}

Please note that:

  • I’m using OnConstruction to create the object
  • The above is using

.

Thank you, where did you find this? Last I checked neither the docs nor intellisense told me there was an override for this function.