Debug Blueprints created via NewObject at runtime

Hello everyone !!

In my current project when someone shoots a character with a particular weapon an effect (something that applies damages of a particular type, ecc) is created and added to the character.
I implemented this via a custom blueprint node that creates a new UObject with a specified class. This object is then added to a UPROPERTY TArray in a character component to avoid GC.



UObject * UJDBlueprintFunctionLibrary::CreateObject(TSubclassOf<UObject> UC)
{

	UObject * created = NewObject<UObject>((UObject*)GetTransientPackage(), UC);
	return  created;
}

I have noticed that blueprints instantiated this way cannot be debugged via the blueprint editor as they do not show up in the debug filter.
By investigating a bit in the engine source I found out that in the debug names generation function (SBlueprintEditorSelectedDebugObjectWidget::GenerateDebugObjectNames line 394) my object to debug is discarded by this piece of code because it does not have have a UWorld in its outers. The outermost object in my object to debug outers chain is the transient package.



do		// Run through at least once in case the TestObject is a UGameInstance
{
	UGameInstance *ObjGameInstance = Cast<UGameInstance>(ObjOuter);

	ObjOuter = ObjOuter->GetOuter();
	ObjWorld = ObjGameInstance ? ObjGameInstance->GetWorld() : Cast<UWorld>(ObjOuter);
} while (ObjWorld == nullptr && ObjOuter != nullptr);

if (ObjWorld)
{
    //Add to debug objects
}

To avoid this I have set the Outer as the current world (obtained via taking a ref to the creating actor in the blueptint node) and everything works as expected and I can now debug my blueprints.



UObject * UJDBlueprintFunctionLibrary::CreateObject(TSubclassOf<UObject> UC, AActor * Creator)
{

	UObject * created = NewObject<UObject>((UObject*)Creator->GetWorld(), UC);
	return  created;
}

What I’m wondering since I’m still a bit of a noob with ue4 is :

  1. Is this the right way of doing it ? Setting that UWorld as the object Outer can create problems with GC ?
  2. Why objects in the transient package cannot be debugged in the bp editor ?

Thanks for taking time to read this :).

Ale.

  1. I still don’t fully understand UE4 packages and in particular when to use the transient package, but no, this shouldn’t create any problems. In fact I would use the creating actor or actor component as the outer object, rather than using the world directly. Both of these will have the world in their outer chain so your debugging should work, and it makes more logical sense, since they are really the owners of the object you’ve created.

  2. I have no idea.

Thanks !!

Yeah It makes more sense to use the actor as parent. Just tested it and it works.

I guess I’ll keep investigating. This is why I love to have the engine source :).