AssetPreview.GetAssetPreview() returning null after entering prefab view via editor script

Im getting an error where AssetPreview.GetAssetPreview() is returning null after editing a prefab programatically via PrefabStageUtility.OpenPrefab(). Im unsure if this is an error happening to do with running a pro builder menu item or not. This is my full code…

string prefabPath = AssetDatabase.GetAssetPath(prefab_ObjectField.value);
PrefabStageUtility.OpenPrefab(prefabPath);
EditorApplication.ExecuteMenuItem("Tools/ProBuilder/Actions/Strip All ProBuilder Scripts in Scene");
StageUtility.GoBackToPreviousStage();

#region Create Preview Texture
Texture2D newT2d = AssetPreview.GetAssetPreview(prefab_ObjectField.value);
byte[] pngBytes = newT2d.EncodeToPNG();

string e = folderPath + "/" + $"{prefab_ObjectField.value.name}_previewTex2D.png";
File.WriteAllBytes(e, pngBytes);

AssetDatabase.Refresh(); // Refresh the AssetDatabase to recognize the new asset
Texture2D importedTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(e);
#endregion

The specific line this is erroring on is

Texture2D newT2d = AssetPreview.GetAssetPreview(prefab_ObjectField.value);

So far i have tried:

  • Setting the object to dirty and saving it via AssetDatabase.SaveIfDirty()
  • Refreshing the AssetDatabase with AssetDatabase.Refresh()
  • Re-importing with AssetDatabase.ImportAsset()

all to no avail, any help would be appriciated!