I need to load a UPaperSprite asset dynamically from path and then use it’s reference with a UPaperSpriteComponent through it’s method SetSprite().
I have no problems creating the UPaperSpriteComponent like this:
UPaperSpriteComponent* Component = NewObject(Parent, UPaperSpriteComponent::StaticClass(), Name);
And I’m currently loading the UPaperSprite with this function:
template <typename ObjClass> static FORCEINLINE ObjClass* LoadObjFromPath(const FName& Path) {
return Cast<ObjClass>(StaticLoadObject(ObjClass::StaticClass(), NULL, *Path.ToString()));
}
FString Path = FString("PaperSprite'/Game/Sprites/Sprite.Sprite'");
Then, the problem starts when I write this line:
Component->SetSprite(LoadObjFromPath<UPaperSprite>(*Path))
If I add that line to the code, then the game starts to loop and memory usage increases until my computer freezes. I have to kill the task everytime. If I remove that line, everything works without crashing.