Hi, I have some trouble updating my project to 4.8 : I have some “ConstructObject is deprecated” in my compilation, and it say to use NewObject() instead.
I find it really weird since I’m using ConstructObject because it what everyone say to use instead of NewObject, and I have no idea how to use NewObject to match my actual code :
UStaticMeshComponent* comp = ConstructObject<UStaticMeshComponent>(UStaticMeshComponent::StaticClass(), this, *node->GetAttribute("name"));
comp->SetStaticMesh(Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), NULL, TEXT("/Engine/EngineMeshes/Cube.Cube"))));
comp->AttachTo(GetRootComponent(), NAME_None, EAttachLocation::KeepWorldPosition);
(this) reference a class that extends AActor()
Thanks for any help!
This change was made in order to simplify UObject creation.
With NewObject, your code will look something like this:
UStaticMeshComponent* comp = NewNamedObject<UStaticMeshComponent>(this, *node->GetAttribute("name"));
If you like to learn more about UObject creation, please go here:
Also, if you want to learn more about 4.8 release notes, this might be useful:
Hope this helped!
Have a great day!
Thanks you, it’s working fine with this !
ConstructObject<> does provide you with more options, but you’re right, there is a compiler warning that suggests it is deprecated.
return NewObject(InParent, Class, Name, Flags);
I think NewNamedObject is deprecated now too in favor of NewObject
It isn’t. Here is how you use it: Objects in Unreal Engine | Unreal Engine 5.0 Documentation