Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

So unity provides gameobject creation of a plane which contains a lot of triangles Unity calculates which is really unneeded for a simple plane. I was following a tutorial on how to do this, but I am getting an error.

Optimized Plane script:

#pragma strict

class OptPlane extends Editor{
@MenuItem("GameObject/Create Other/Opt Plane")

static function Init (){
    var customPlane : GameObject = new GameObject("Optimized Plane");
    var meshFilter : MeshFilter  = customPlane.AddComponent(MeshFilter);
    customPlane.AddComponent(MeshRenderer);

    var destination : String = "Asset/Model/OptimizedPlane.asset";
    var mesh : Mesh = AssetDatabase.LoadAssetAtPath(destination, Mesh);

    if(! mesh){
        mesh      = Mesh();
        mesh.name = 'Optimized Plane';

        var vertices : Vector3[]  = [Vector3(-1,0,1), Vector3(1,0,1), Vector3(1,0,-1), Vector3(-1,0,-1)];
        var uv       : Vector2[]  = [Vector2(-1,1), Vector2(1,1), Vector2(1,-1), Vector2(-1,-1)];
        var tangents : Vector4[]  = [Vector4(-1,0,1,1), Vector4(1,0,1,1), Vector4(1,0,-1,1), Vector4(-1,0,-1,1)];
        var triangles: int[]      = [0,1,3,3,1,2];

        mesh.vertices  = vertices;
        mesh.uv        = uv;
        mesh.tangents  = tangents;
        mesh.triangles = triangles;

        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
        mesh.Optimize();
        AssetDatabase.CreateAsset(mesh, destination);
        AssetDatabase.SaveAssets();
    }

    meshFilter.mesh = mesh;
    Selection.activeObject = customPlane;
}

Warning: UnityException: Creating asset at path Asset/Model/OptimizedPlane.asset failed. OptPlane.Init () (at Assets/Editor/OptPlane.js:32)

I understand that it can't create it to this location I sent it, but from the tutorial he did nothing special besides create a "Model" folder and it just worked for him. Also, what is this .asset extension? I am just guessing it is what Unity uses to create objects in the scene or something.

Here is the link for reference. http://www.youtube.com/watch?feature=player_detailpage&v=ojEAHx_vY3U#t=1952s

share|improve this question
Which is line 32? – Byte56 Jan 15 at 22:40
1  
Shouldn't it be "Assets/Model/whatever.asset" and not Asset/etc – Tetrad Jan 15 at 22:42
line 32: AssetDatabase.CreateAsset(mesh, destination); – zyeek Jan 15 at 22:47
@Tetrad You are right, thanks. Problem fixed. – zyeek Jan 15 at 22:49

closed as too localized by Byte56, Trevor Powell, michael.bartnett, Tetrad Jan 16 at 5:43

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.