Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


SetMainObject(Object)

Sets the main object for import.
Read time 1 minuteLast updated 13 days ago

Definition

public void SetMainObject(Object obj)

Parameters

The object to be set as the main object. This object must already be added with the AssetImportContext.AddObjectToAsset method.

Remarks

Use this method to specify the main object in the asset file.
Note: Before invoking this method, the object that is passed as the argument must first be added with AssetImportContext.AddObjectToAsset. If this method is not called, then one of the objects added through AssetImportContext.AddObjectToAsset is arbitrarily promoted as the main object. If objects of type GameObject are added through AssetImportContext.AddObjectToAsset, then AssetImportContext.SetMainObject must refer to one of these objects. Passing a different type of object results in the selection being ignored and an arbitrary GameObjects is promoted as the main object.
Note: This method returns an error when used in an AssetPostprocessor because the Importer sets the main object later in the import process.