I’m working on a system where I want to load a series of datatables, each with corresponding to a scripted conversation in my game. I think keep a list of all those assets in a TMap with their identifier and a soft object pointer.
That said, I appear to be running into garbage collection troubles - there’s either something about TMaps and garbage collection that I’m not understanding, or perhaps I’m misusing soft object pointers and should be using another method for pointing to the loaded object to prevent this from happening. Thoughts?
Here’s some sample code:
// In my .h file, declarations:
UPROPERTY()
TMap<int, TSoftObjectPtr> ChapterConvoAssets;
// Loading the asset from an asset manifest:
// Load Convos
for (auto& Entry : NewAssets->ChapterConvoAssets)
{
FSoftObjectPath TablePath = FSoftObjectPath(*Entry.Value);
TSoftObjectPtr<UDataTable> Table = Cast<UDataTable>(TablePath.TryLoad());
if (Table)
{
ChapterConvoAssets.Add(Entry.Key,Table);
UE\_LOG(LogTemp, Warning, TEXT("Loaded convo asset: %s"), \*Entry.Value)
}
}