Problem getting mesh vertices

I’m trying to get the vertices and triangles arrays of a mesh at start, this is done for the car AI control in my racing games.

Now I want to share part of this with the community and I’m making a project with basic car physics and basic AI, but …

Why this give me an error?

private var trackVertices;
private var trackTriangles;


function Start () {
	var mesh : Mesh = GetComponent(MeshFilter).sharedMesh;
	trackVertices = mesh.vertices;
	trackTriangles = mesh.triangles;
	print(trackVertices.length);
}

but this one not?:

function Start () {
	var mesh : Mesh = GetComponent(MeshFilter).sharedMesh;
	var trackVertices = mesh.vertices;
	var trackTriangles = mesh.triangles;
	print(trackVertices.length);
}

The problem is I want to get the vertices and triangles arrays to another script as variables, and in the first case it won’t work and in the second case I cannot get it externally.

The fun part is I made a dozen setups with the “wrong code” (the first one) and it worked fine, but when I simplified the scripts it doesn’t.

Thank you

first thing that sticks out is both cases have the arrays as private vars. can you get private vars from another script? can’t say i’ve tried.

Aside from the private var thing which pete mentioned:

private var trackVertices;
private var trackTriangles;

These are dynamically typed…if you’re not using type inference, then you should specify the type:

private var trackVertices : Vector3[];
private var trackTriangles : int[];

Otherwise it will be very slow. If you’re doing that in your other scripts, that could well be the cause of the LowRider slowness that some people are experiencing.

If you want to have variables accessible from other scripts but not show in the inspector, then do this:

@HideInInspector
var trackVertices : Vector3[];
@HideInInspector
var trackTriangles : int[];

–Eric

You both are allright. Sometimes when programming I get some kind of obfuscation and cannot see the evident.

It’s working now.