x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to Unload Asset in memory loaded by StreamableManager

wo load asset by objectlibrary and streamablemanager . It's always in memory.I can't Unload it using various methods.

Loading process:/使用ObjectLibrary 获取指定路径下的资产信息 AssetData。 使用AssertRegistry 也能获取资源的AssetData void AAssetPlayerController::TestObjectLibrary() { if (!ObjectLibrary) { ObjectLibrary = UObjectLibrary::CreateLibrary(UObject::StaticClass(), true, true); ObjectLibrary->AddToRoot(); }

 int AssetCount = ObjectLibrary->LoadBlueprintAssetDataFromPath("/Game/Test");

 UE_LOG(LogTemp, Warning, TEXT("Asset Count: %d"), AssetCount);

}

//将AssetData信息转换为FSoftObjectPtr或者FSoftObjectPath,然后才能用StreamableManager进行资源的异步加载 void AAssetPlayerController::TestStreamableManagerAsyncLoad() { FStreamableManager* streamable = new FStreamableManager(); TArray assetdata; ObjectLibrary->GetAssetDataList(assetdata);

 TArray<FSoftObjectPath> ItemsToStream;

 for (int i = 0; i < assetdata.Num(); i++)
 {
     ItemsToStream.AddUnique(assetdata[i].ToSoftObjectPath());
 }
 if (ItemsToStream.Num() > 0)
 {
     streamable->RequestAsyncLoad(ItemsToStream, FStreamableDelegate::CreateUObject(this, &AAssetPlayerController::KeepReference));
 }

}

//将加载的资源保持引用,否则在这个函数调用完成之后就会销毁 void AAssetPlayerController::KeepReference() { TArray assetdata; ObjectLibrary->GetAssetDataList(assetdata);

 TArray<FSoftObjectPath> ItemsToStream;

 for (int i = 0; i < assetdata.Num(); i++)
 {
     ItemsToStream.AddUnique(assetdata[i].ToSoftObjectPath());
 }

     myobject.Add(assetdata[0].GetAsset());
 
     GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Cyan, "Async Load Object OK");

}

-------------------------------------------I can unload it -------------------------------------------------------------------------------------------- void AAssetPlayerController::IsContainInMemory() { TArray myAssetData; if (!ObjectLibrary) { ObjectLibrary = UObjectLibrary::CreateLibrary(UObject::StaticClass(), true, GIsEditor); ObjectLibrary->AddToRoot(); } ObjectLibrary->LoadBlueprintAssetDataFromPath("/Game/Test"); ObjectLibrary->GetAssetDataList(myAssetData); if (myAssetData[0].IsAssetLoaded()) { GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Cyan, "Async Remain In Memory");

 }
 else
 {
     GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Cyan, "Async Don't In Memory");
 
 }

}

void AAssetPlayerController::UnLoadAsset() { TArray myAssetData; ObjectLibrary->GetAssetDataList(myAssetData);

 FStreamableManager* streamable = new FStreamableManager();
 myobject[0] = NULL;
 streamable->Unload(myAssetData[0].ToSoftObjectPath());

 FString Tip = "Start Asset Unload" + myAssetData[0].GetPrimaryAssetId().ToString();
 GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Cyan,Tip);

}

Help me .Thanks vary much!!

Product Version: UE 4.19
Tags:
more ▼

asked Apr 15 '18 at 03:26 AM in C++ Programming

avatar image

宗同贵
13 1 3 6

(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question