# LoadMainAssetAtPath(string)

> Obtains the main asset object at assetPath.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.3/script-reference/unityeditor.md)
* **Assembly:** UnityEditor

```csharp
public static Object LoadMainAssetAtPath(string assetPath)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Filesystem path of the asset to load.

### Returns

| Type                                                            | Description                                   |
| --------------------------------------------------------------- | --------------------------------------------- |
| [Object](/engine/6000.3/script-reference/unityengine/object.md) | Returns the main asset object at `assetPath`. |

### Remarks

The main asset is the asset at the root of a hierarchy (such as a Maya file which might contain multiple meshes and GameObjects). All paths are relative to the project folder, for example: `Assets/MyTextures/hello.png`.

Additional Resources: [AssetDatabase.LoadAssetAtPath](/engine/6000.3/script-reference/unityeditor/assetdatabase/loadassetatpath.md), [AssetDatabase.LoadAllAssetsAtPath](/engine/6000.3/script-reference/unityeditor/assetdatabase/loadallassetsatpath.md), [AssetDatabase.LoadAllAssetRepresentationsAtPath](/engine/6000.3/script-reference/unityeditor/assetdatabase/loadallassetrepresentationsatpath.md).

### Examples

```csharp
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class MyPlayer : MonoBehaviour
{
    [MenuItem("AssetDatabase/Assign Materials To Models")]
    static void AssignGunMaterialsToModels()
    {
        var materials = new List<Material>();
        //Get all the materials that have the name gun in them using LoadMainAssetAtPath
        foreach (var asset in AssetDatabase.FindAssets("t:Material gun"))
        {
            var path = AssetDatabase.GUIDToAssetPath(asset);
            materials.Add((Material)AssetDatabase.LoadMainAssetAtPath(path));
        }

        var materialID = 0;
        //Assign gun materials to their corresponding models MeshRenderer
        foreach (var asset in AssetDatabase.FindAssets("t:Model Gun"))
        {
            if (materialID >= materials.Count) materialID = 0;
            var path = AssetDatabase.GUIDToAssetPath(asset);
            var material = materials[materialID++];
            material.shader = Shader.Find("Standard");
            var modelMesh = (MeshRenderer) AssetDatabase.LoadAssetAtPath(path, typeof(MeshRenderer));
            modelMesh.sharedMaterial = material;
        }
    }
}
```
