NewObject<ActorComponent> does not work in Packaged Version

Hello there :slight_smile:

This custom Blueprint node returns “null” in Packaged Version only but I’m not crashing. I have no problems in Standalone or Play In Editor.

I’m printing the return value in Blueprint.

This is written in a Plugin’s Blueprint Library.
It’s working perfectly when written in a Blueprint Library in the project source code.

I just added my plugin to the module list and it’s working.



UActorComponent* MyLibrary::AddCustomActorComponent(AActor* TargetParent, TSubclassOf<UActorComponent> NewComponent)
{
FName TempName = NewComponent->GetFName();
UActorComponent* TempNewComponent = NewObject<UActorComponent>(TargetParent, NewComponent, TempName);
TempNewComponent->RegisterComponent();
return TempNewComponent;
}

What am I doing wrong?
(I removed the null pointer verification along the way to isolate the issue).

So it looks like I’m not doing something wrong here, but maybe in my Plugin’s settings?

Thanks in advance for any answer, good luck and have fun in your projects everyone.

VS Community 2015, Win64 Development Build, Windows 10, UE4 4.15.3

I’d suggest you breakpoint into the NewObject call and see what’s going on in there, if this is possible in your run-mode.

I don’t think I can use Breakpoints to debug in packaged version of my game. At least I don’t know how.

It looks like something is spawned, else the line “TempNewComponent->Register” would crash but I don’t manage to output to my logs in Packaged Mode.

There is something I forgot to talk about: these lines of codes are written in a Blueprint Library of a Plugin.

If I write the library in the project source code, it’s working as intended: the Blueprint nodes do return me the spawned component.

Swap this



FName TempName = NewComponent->GetFName();
UActorComponent* TempNewComponent = NewObject<UActorComponent>(TargetParent, NewComponent, TempName);


for this:



UActorComponent* TempNewComponent = NewObject<UActorComponent>(TargetParent, NewComponent);


You shouldn’t need to give the component a name. I believe the names are meant to always be unique. Additionally, you can attach the debugger to a packaged game by first packaging it (I suggest a DebugGame version, and ensuring that ‘Include Debug Files’ is included when packaging) - then switch to ‘DebugGame’ in visual studio and start the debugger.

Thanks for the support guys!

I’m trying your method right now TheJamsh.

And I have another lead, maybe I need to include the Plugin in my project’s target.cs file (but I’d like not to since I’d like it to be imported in pure blueprint projects).

EDIT:

It’s still not working in packaged version. But at least it’s cleaner, thanks!

I’ll try my second lead and adding the debugger.

EDIT2.
I just added my plugin to the module list and it’s working.

Can it work without doing this in a blueprint-pure project?
I’ll create a new thread for that, thank you very much for your answers.

This thread can be marked as resolved!