

Is this object part of a Prefab that cannot be edited? Returns true if the given object is part of any kind of Prefab. Is the GameObject the root of a Prefab instance, excluding nested Prefabs? Returns true if the given object is part of an instance where the PrefabInstance object is missing but the given object has a valid corresponding object. Returns true if the given modification is considered a default override. Is the GameObject the root of any Prefab instance? Is this GameObject added as a child to a Prefab instance as an override?

Is this component added to a Prefab instance as an override? Instantiates the given Prefab in a given Scene. Instantiate an asset that is referenced by a Prefab and use it on the Prefab instance. Returns true if the given Prefab instance has any overrides. Returns a list of objects with information about removed component overrides on the Prefab instance.ĭetermines whether the object Prefab asset contains any MonoBehaviours with missing SerializeReference types. Retrieves the PrefabInstance object for the outermost Prefab instance the provided object is part of.ĭetermines whether a Prefab instance is properly connected to its asset.Įxtracts all modifications that are applied to the Prefab instance compared to the parent Prefab. Retrieves an enum value indicating the type of Prefab Asset, such as Regular Prefab, Model Prefab and Prefab Variant. Retrieves the asset path of the nearest Prefab instance root the specified object is part of. Retrieves the GameObject that is the root of the outermost Prefab instance the object is part of. Retrieves a list of objects with information about object overrides on the Prefab instance. Retrieves the GameObject that is the root of the nearest Prefab instance the object is part of. Retrieves the icon for the given GameObject. Retrieves the corresponding object of the given object from a given Prefab Asset path. Retrieves the corresponding asset object of source, or null if it can't be found. Retrieves the object of origin for the given object. Retrieves a list of PrefabUtility.AddedGameObject objects which contain information about added GameObjects on the Prefab instance. Retrieves a list of PrefabUtility.AddedComponent objects which contain information about added component overrides on the Prefab instance. If prefabRoot is not a valid Prefab asset root GameObject, an ArgumentException is thrown. Retrieves the root GameObjects for all instances of the Prefab asset with root prefabRoot found in all currently loaded scenes. Removes the component from the Prefab Asset which has the component on it. Return Selection.activeGameObject != null & ! EditorUtility.IsPersistent( Selection.activeGameObject) Īpplies the added component to the Prefab Asset at the given asset path.Īpplies the added GameObject to the Prefab Asset at the given asset path.Īpplies the added GameObjects to the Prefab Asset at the given asset path.Īpplies all overridden properties on a Prefab instance component or GameObject to the Prefab Asset at the given asset path.Īpplies all overrides on a Prefab instance to its Prefab Asset.Īpplies a single overridden property on a Prefab instance to the Prefab Asset at the given asset path. Disable the menu item if no selection is in place. PrefabUtility.SaveAsPrefabAssetAndConnect(gameObject, localPath, InteractionMode.UserAction, out prefabSuccess) ĭebug.Log("Prefab was saved successfully") ĭebug.Log("Prefab failed to save" + prefabSuccess) Create the new Prefab and log whether Prefab was saved successfully. LocalPath = AssetDatabase.GenerateUniqueAssetPath(localPath) Make sure the file name is unique, in case an existing Prefab has the same name. String localPath = "Assets/Prefabs/" + gameObject.name + ".prefab" If (! Directory.Exists("Assets/Prefabs"))ĪssetDatabase.CreateFolder("Assets", "Prefabs") and name it as the GameObject's name with the.

Create folder Prefabs and set the path as within the Prefabs folder, Loop through every GameObject in the array aboveįoreach ( GameObject gameObject in objectArray) GameObject objectArray = Selection.gameObjects

Keep track of the currently selected GameObject(s) Creates a new menu item 'Examples > Create Prefab' in the main menu. It is placed in the root Assets folder. Use it to create Prefab(s) from the selected GameObject(s). This script creates a new menu item Examples>Create Prefab in the main menu.
