Quantcast
Channel: Answers for "Cannot modify Prefab"
Viewing all articles
Browse latest Browse all 6

Answer by msknapp

0
0
Ok so here is an extremely simplified version of my pseudo-code that does not work: String dirPath = "Assets\\Shapes\\"+cellName; String destFilePath = dirPath+"\\"+cellName+".fbx"; AssetDatabase.GenerateUniqueAssetPath(destFilePath.Replace("\\","/")); DirectoryInfo destDir = new DirectoryInfo(Directory.GetCurrentDirectory() + "\\"+dirPath); if (! destDir.Exists) destDir.Create(); FileUtil.CopyFileOrDirectory(fileInfo.ToString(),destFilePath.Replace("\\","/")); AssetDatabase.Refresh(); String s = dirPath.Replace("\\","/")+"/"+cellName+".fbx"; UnityEngine.Object[] assets = AssetDatabase.LoadAllAssetsAtPath(s); AssetDatabase.StartAssetEditing(); foreach (UnityEngine.Object asset in assets) { if (! (asset is GameObject)) continue; GameObject gameObjectAsset = (GameObject)asset; // there is code here to modify the position and rotation of the game object asset... // from the debugger I have confirmed that the changes were made to the object correctly. EditorUtility.SetDirty(gameObjectAsset); EditorUtility.SetDirty(gameObjectAsset.transform); EditorUtility.SetDirty(gameObjectAsset.transform.position); } AssetDatabase.StopAssetEditing(); AssetDatabase.SaveAssets(); // I select the asset in my project view, under the shapes folder. // I look in the inspector at the objects I build, // and the changes I made to the transform are not there.

Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images