PrefabUtility.CreatePrefab() results in "not a valid asset file name" error?
I'm trying to create a new prefab in an editor script based on a pre-existing GameObject in the scene by using UnityEditor.PrefabUtility.CreatePrefab(pathStr, obj)
. The specific path I'm using for testing is Assets\TreeGen\Tests\Baked Trees\Tree1\Tree1Original.prefab; as far as I can tell based on Google searches, this is the correct way to pass in the prefab name (i.e. using a path starting in "Assets", and including the ".prefab" at the end). However, I get an error:
'Assets\TreeGen\Tests\Baked Trees\Tree1\Tree1Original.prefab' is not a valid asset file name.
UnityEditor.PrefabUtility:CreatePrefab(String, GameObject)
CurveMeshEditor:BakeToFile(String) (at Assets/TreeGen/Editor/CurveMeshEditor.cs:124)
CurveMeshEditor:OnInspectorGUI() (at Assets/TreeGen/Editor/CurveMeshEditor.cs:78)
UnityEditor.DockArea:OnGUI()
Am I using this method wrong?
Answer by CommanderThrawn · Dec 10, 2016 at 01:01 AM
Looks like the problem is related to using "/" vs "\". Try replacing with "/" and see if it works, looks like it did for me. Good luck!
Answer by ChrissTman · Aug 31, 2016 at 12:24 PM
Ye, me to :/ and i found even your Redit post and my path has only 82 chars, so we will have to just wait for bugfix.
Im just curious, how did you do the workaround to this whole problem that doesn't involve prefabs ?
It's very specific to my project; I just decided not to use prefabs at all. It's part of an editor plugin, and the prefabs were just a bit of convenience that I did so the user wouldn't have to make prefabs manually.
Your answer
Follow this Question
Related Questions
PrefabUtility.RevertPrefabInstance() not working 2 Answers
How to add a component from a Custom Editor object field to a Prefab ? 1 Answer
Comparing a gameObject's source prefab with a prefab 0 Answers
C# Unity class Arrays for Editor GUI textures. Beginner problem. 0 Answers
Override constructor of list of classes when creating a new element from the inspector 0 Answers