UE5 bug: ObjectLibrary doesn't find newly created assets

There seems to be a bug in the Unreal Engine 5.0 Preview.
When creating new assets at runtime and saving them on disk, they do actually get saved correctly, but ObjectLibaries can’t find these assets.

First create an asset:

UObject* MyAsset = NewObject<UMyAsset>(...);
UPackage::Save(MyAsset, ...);

Then try to load the freshly created asset (its FAssetData) using an ObjectLibrary:

UObjectLibrary* ObjectLibrary = UObjectLibrary::CreateLibrary(UMyAsset::StaticClass(), false, false);
ObjectLibrary->AddToRoot();
ObjectLibrary->LoadAssetDataFromPath(AssetDirectory);
ObjectLibrary->GetAssetDataList(AssetArray);

I tested this on UE5.0 Preview 1 in the editor and the AssetDataList is emtpy. When I stop the game and start it again, the AssetDataList does contain the asset. So it seems like the assets that you create at runtime are not recognized by the engine anymore after starting the game (so probably after cooking).

One way around this is to force the AssetRegistry to rescan the directory:

TArray<FString> PathsToScan = TArray<FString>();
PathsToScan.Add(AssetDirectory);
const FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
AssetRegistryModule.Get().ScanPathsSynchronous(PathsToScan, true);

However, I am not sure if you are supposed to do that, somehow doesn’t feel right.