Why does Unity hang after entering in a trigger?

using UnityEngine;
using UnityEditor;

public class Script: MonoBehaviour
{

public GameObject inf;

void OnTriggerEnter()
{
    GameObject assetRoot = inf;
    string assetPath = AssetDatabase.GetAssetPath(assetRoot);
    GameObject contentsRoot = PrefabUtility.LoadPrefabContents(assetPath);
    foreach (Transform child in contentsRoot.transform)
    {
        child.gameObject.SetActive(true);
    }
    PrefabUtility.SaveAsPrefabAsset(contentsRoot, assetPath);
    }
}

When I enter the trigger with this script, unity freezes and the endless loading begins. As I understand it, unity freezes after executing the command “PrefabUtility.SaveAsPrefabAsset(contents Root, assetPath);”. Is it possible to make the execution of functions in the script without freezes?

using UnityEngine;
using UnityEditor;

public class Script : MonoBehaviour
{
public GameObject inf;
public bool entered;

void Update()
{
    if (entered == true)
    {
        GameObject assetRoot = inf;
        string assetPath = AssetDatabase.GetAssetPath(assetRoot);
        GameObject contentsRoot = PrefabUtility.LoadPrefabContents(assetPath);
        foreach (Transform child in contentsRoot.transform)
        {
            child.gameObject.SetActive(true);
        }
        PrefabUtility.SaveAsPrefabAsset(contentsRoot, assetPath);
        entered = false;
        Destroy(gameObject);
    }
}

private void OnTriggerEnter(Collider other)
{
    entered = true;
    }
}

While no one answered me, I found a clever way. I know it’s not very practical, but what can you do when there are a lot of bugs in unity.