NewObject with empty name can't be used to create default subobjects

So, I’m trying to upgrade my project, but the last error that I’m stuck on is

“NewObject with empty name can’t be used to create default subobjects (inside of UObject derived class constructor) as it produces inconsistent object names. Use ObjectInitializer.CreateDefaultSuobject<> instead.”

There is nothing more specific in the log, so I can’t narrow it down. I have added a name to all NewObject<>() calls in constructors, but I still get the error. I have checked my code for UMaterialInstanceDynamic::Create() but I’m not using it.

Does anyone know what potential function calls would give this error if used in a constructor?

1 Like

Hello MasterHunter,

There are many things that could cause this message to appear. It would be best to see your constructors where this is occurring rather than taking multiple stabs in the dark at what the issue is. Could you either upload the code files or make a pastebin link with the constructors?

Hey

This is a fairly big project (100+ .cpp files), so I was hoping to avoid uploading any code.

I was hoping that there was a list of functions, that when called in a constructor, are known to cause this crash in 4.8.
The project works in 4.7, but we were hoping to upgrade to at least 4.9…

Is there any particular reason you’re using NewObject instead of CreateDefaultSubobject? As NewObject is meant to dynamically allocate memory for new objects/variables, I don’t believe it can be used in the constructor at all.

As far as a list goes, there isn’t really a comprehensive list of functions that won’t work in the constructor. One example would be SpawnActor but there are many others.

Upgrading to a previous version of Unreal deprecated another function for the NewObject function. It’s not all my code, so I’d assume that because it worked before (and there were no warnings not to) they used something other than CreateDefaultSubobject.

And to my understanding, you can use NewObject as long as it has a name passed to it. But if I get a chance, I’ll change those (yet again lol) to CreateDefaultSubobject to see if it helps.

Otherwise, that’s unfortunate. I would’ve thought these upgrade issues would’ve been better documented…

The usage has been changed multiple times throughout the latest version updates. Usually, deprecation messages are listed in code, like the one you referenced in your original posts and sometimes in the Release Notes. Have you given CreateDefaultSuboject a try yet? I’m interested to know if that worked out better for you.

We haven’t tried to fix it further. It turns out 4.7 broke something with the behaviors and we just don’t have the time to fix that anymore or fix the NewObject error