Edit: Forgot to add the relevant code, the post should make more sense now!
Edit2: I think the issue might be due to LoadAssetDataFromPath not detecting the blueprints as TSubclassOf() after packaging. How can I make it detectable in both editor and the packaged game? I tried using StaticClass instead, but then it doesn’t find anything, I guess because the blueprints generate new classes instead of being instances of the parent class.
UObjectLibrary* ObjectLibrary = UObjectLibrary::CreateLibrary(UWidgetBlueprintGeneratedClass::StaticClass(), true, false);
ObjectLibrary->LoadAssetDataFromPath(Path);
TArray<FAssetData> AssetDatas;
ObjectLibrary->GetAssetDataList(AssetDatas);
for (const FAssetData& AssetData : AssetDatas)
{
TSoftObjectPtr<UWidgetBlueprintGeneratedClass> SoftRef(AssetData.ToSoftObjectPath());
TSubclassOf<T> HardRef = static_cast<TSubclassOf<T>>(SoftRef.LoadSynchronous());
.... now you can create a widget....
.... didn't check if it is same for UBlueprints, but you could experiment with UBlueprint::StaticClass and UObject::StaticClass...
The idea is Game is not treating blueprint files the same way as Editor does. So you need to manipulate not hard references but files of certain type. In my case it was WidgetBlueprints files which had type of UWidgetBlueprintGeneratedClass
but this solution is not perfect…
If anyone has a better solution please tell me…