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 :
- Is this the right way of doing it ? Setting that UWorld as the object Outer can create problems with GC ?
- Why objects in the transient package cannot be debugged in the bp editor ?
Thanks for taking time to read this :).
Ale.