---
title: "Unity2018编辑模式通过GameObject查找prefab"
author: "贝壳水母"
date: "2019-07-18T09:58:46Z"
tags: []
categories: ["移动开发"]
slug: "unity2018-gameobject-prefab"
draft: false
lastmod: "2019-07-18T09:58:46Z"
id: 2442765
url: "https://shineonly.iteye.com/blog/2442765"
---

```c#

var prefabObj = PrefabUtility.GetCorrespondingObjectFromSource(childTrans.gameObject);
if (!prefabObj)
{
    continue;
}

string prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(prefabObj);
if (string.IsNullOrEmpty(prefabPath))
{
    Debug.Log("cant find prefabPath");
    continue;
}

```