Is it possible to write an editor script that will create a new scene, add an empty object and then copy an fbx file into that object?
I can’t find any examples that make it seem like this is possible but does anyone know any better?
Is it possible to write an editor script that will create a new scene, add an empty object and then copy an fbx file into that object?
I can’t find any examples that make it seem like this is possible but does anyone know any better?
EditorApplication.NewScene creates a new scene and the GameObject is created in the same way as it would be at runtime. I’m guessing you actually want to add the mesh imported from the FBX file rather than do something with the file itself. How you access the mesh asset will depend on whether it always has the same name or if it must be selected first, etc. However, it is likely you will use AssetDatabase.LoadAssetAtPath to get a reference to the mesh once you’ve located it.
The fbx file contains a number of objects and I’d like to mimic what happens when you drag the whole fbx file into the scene.
From what you are saying would I need to script adding each object in the fbx file to the scene one at a time and then assiociate each one with a mesh in the fbx file, can I do it all in one go?
If I need to make each object can I get that information direct from the fbx file or will I need to do that externally and read in the information via an xml file or something similar?
The easiest way to go would probably be to parent all the object in the FBX file to a single object. You could then extract the child objects and add them to the scene. I don’t think Unity has any API to get directory data from an FBX file but passing this data in separately with an XML text asset might be an option.
Hey, I’ve been trying to us EditorApplication.NewScene() in an Editor script, and it crashes every time. Has anyone come across this before?