MenuItem Question

Almost got this working, this is a hackish way of trying to break a prefab connection in one click. Can anyone see why it wouldn’t work? Thanks

@MenuItem ("DW3D_FX/BreakPrefab")

static function BreakPrefab () {
    
    var objs = Selection.gameObjects;
    
    for (var go : GameObject in objs) 
    {
        go.AddComponent(AudioSource);
        
        Debug.Log ("Prefab Connection is now broken. Object is now independent");
        
        DestroyImmediate(go.GetComponent(AudioSource));
    }
}

So my fun solution:

@MenuItem ("DW3D_FX/BreakPrefab")

static function BreakPrefab () {
    
    var objs = Selection.gameObjects;
    
    for (var go : GameObject in objs) 
    {
        go.AddComponent(tempScript);
        
    }
}

which loads this onto said object:

@script ExecuteInEditMode
function Start () {
    print("Prefab Connection Broken");
    DestroyImmediate(this);
}

But doing a test build to webby I get this error:
BCE0064: No attribute with the name ‘MenuItem’ or ‘MenuItemAttribute’ was found (attribute names are case insensitive).

err, whats that about?

Thanks
AC

This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add “using UnityEditor;” at the beginning of the script.

:slight_smile:

Heh heh 5 months later. I must have figured that out. Thanks though

-or is it 11 months? Cant tell, different countries put the days and months in different order.

AC