Prefab and Variant Generation
About this Plugin
When you purchase an asset from the asset store, and depending on what you are buying, it comes with a series of prefabs and example items that were created by the asset owner. In this case we are talking about models and materials that comprise your game world. If we use Synty as an example (see below image) you can see that under the prefabs folder we have Dogs and Props. These folders will contain preconfigured models that are already setup for you. This is great since you can get a headstart on developing your game, without having to mess with prefabs. This is where start of the problem begins and what this asset is designed to resolve.
When you modify the prefabs that were created by the asset owner, and use these in your game, you run the risk of losing all modifications in your files. Unity utilizes a GUID system to identify an asset when in usage. This GUID is unique between all of the assets that are loaded in your game. If you update or reimport the asset again, when the asset owner updates it, to readd something you imported or whatever the case may be, you run the risk of losing all your work on those items. Since you are working with the original items, Unity will see those have changed and mark them as replaceable when you reimport the original asset pack. Moving them from the original folder does not prevent the items from being overwritten since Unity does not care about asset paths for assets. The only way to prevent this, is to copy the item, create a new item or to generate your own set of prefabs and variants from the items.
This tool will create a copy of the original item, and then it will create a variant of this copy for you to work with. In some cases, where you have additional materials that will work on the models, you can have the system automatically generate a series of models for export for each color variation you have. These variants are the items you will use in your game. This will allow you to make any modification you want, with the ability to update your assets or reimport them without worry you will lose your changes. As long as the original asset still exists, your variants will work.
Prefab Variant Item
To start the process, we will begin by downloading and importing whatever asset you want to generate. This can be any asset that has a prefab already that you want to generate your own items from.
Important Note: Since we are wanting to generate a final mob item and not have to modify a whole bunch of various mobs, it is really important to setup your mobs properly, before you run this script on them. Have all of the Atavism scripts on the assets configured prior to working with this.
Folder to Process
This is the original folder that contains the original asset prefabs you will be working with. In our example we are working with the Dogs folder in the Prefabs folder of the original Synty Dogs asset shown above.
Folder to Save
This is the folder where you will be saving either your prefabs or variants. It is always important to fill out a folder for each, even if you will not be saving the parent prefabs.
In some instances, such as a character, it is not important to create a parent prefab and will sometimes lead to too many copies of items. Since you should use this for any asset you will be placing in your game, this allows you the option of selecting the original asset as the variant copy or the copied parent prefab as the variant copy.
Save Parent Prefabs
This option allows you the option to skip creating the Prefabs, which are called parent prefabs for this purpose. When enabled, this will create a copy of the original artwork and then create the variant from this copy. When doing this, it decouples the ability to update the original artwork and have it adjust your variant when the original updates.
In some instances, such as a character, it is not important to create a parent prefab and will sometimes lead to too many copies of items. Since you should use this for any asset you will be placing in your game, this allows you the option of selecting the original asset as the variant copy or the copied parent prefab as the variant copy.
Name to Cleanup
This allows you the option to have the system clean up and remove text that appears in the name of assets. It will simply remove this text if it appears in the name at all, it will not replace it with anything else.
Material Variations
If you add a material variation, the system will generate a variant for each material variation you place in this position. You can place as many as you wish here, for as many material variations you have.
Important Note: If you are generating Mobs, consider using the option in the mob generator instead. This will lead to less overall prefabs in your environment.
Process This
This allows you to toggle the ability to generate this section of items. When disabled, it will ignore building these items that are configured.
Note: Unity has a hard time dropping the memory requirements for long running processes. It is important to make sure you are breaking up your generations into manageable chunks. Since you can generate items very rapidly, but long running loops create an issue, you should take advantage of this feature to keep your run times short, but keep your game items configured for future runs.
API documentation
Class: PrefabVariant
This class represents the settings for building a prefab variant.
Properties
folderToProcess
: (UnityEngine.Object) The folder that the script will parse and build objects from for the folder processing.folderToSavePrefabs
: (UnityEngine.Object) Your project specific folder for saving the parent prefab objects.saveParentPrefabs
: (bool) A flag indicating if the parent prefab objects should be saved.folderToSaveVariants
: (UnityEngine.Object) Your project specific folder for saving the variant prefab objects.nameToCleanup
: (string) Name extention to the existing prefab name, a good way to add variant identifiers, leave empty to prevent adding to the objects name.materialVariations
: (List) A list of materials to use as variations for the prefab.processThis
: (bool) A flag indicating if this prefab variant should be processed.
Class: PrefabVariantGenerationSystem
This class provides a system for generating prefab variants.
Properties
PrefabVariantList
: (List) The list of prefab variants to be processed.objectToBuild
: (GameObject) The single item you wish to build, instead of processing an entire folder structure.
Methods
ProcessFolder(parents = false)
: Processes the folder of prefab variants.BuildVariant(prefab, nameSuffixString, PrefabVariantItem, thisMaterial)
: Builds a variant prefab object.SaveParentPrefab(prefab)
: Saves the parent prefab object.BuildParentObject(prefab, variantPrefab, nameSuffixString, PrefabVariantItem, justtoofoolVS = false)
: Builds a parent prefab object.ApplyMaterial(prefab, itemMaterial)
: Applies a material to the prefab.BuildVariants(prefab, nameSuffixString, folderPath, folderName)
: Builds a variant prefab object and saves it to a specified folder.