Hello I wanted to compile an iOS build from my game and I got build errors… how can I correct?
- mesh is not a member of UnityEngine.Component
- sharedMesh is not a member of UnityEngine.Component
- gameObject is not a member of UnityEngine.Object
Hello I wanted to compile an iOS build from my game and I got build errors… how can I correct?
Read up on using #pragma strict
In short: mobile devices do not support unitys javascript’s dynamic type inference to convert your code into statically typed code. So where you are used to automatic typecasting you’ll have to do it yourself now. The reason you get these errors when building and not in the editor is because your compiler thinks he is allowed to use type inference, but when building for mobile he knows he isn’t. To ‘tell’ the compiler not to use type inference, so you can see what you’re doing wrong in the editor, write #pragma strict on the top of your script.
The errors you are getting here is that you are saying, for instance:
var someMeshFilter : MeshFilter = gameObject.GetComponent( MeshFilter);
The problem is, GetComponent returns a Component, not a MeshFilter. MeshFilter inherits from Component, and through type inference the compiler realises you wanted it to return a MeshFilter, not ‘just’ a Component. This does not happen when you use strict typing, when you use strict typing it throws an error because Component is not a MeshFilter.
There are two options for fixing this. Either tell the compiler that the component you want is of a specific type:
var someMeshFilter : MeshFilter = gameObject.GetComponent( MeshFilter) as MeshFilter;
or use a special version of GetComponent (the version everybody should nearly always be using, by the way) which doesn’t return a compontent but it returns the correct type:
someMeshFilter : MeshFilter = gameObject.GetComponent.<>( MeshFilter);
So on the line where you get the error “mesh is not a member of UnityEngine.Component” replace:
gameObject.GetComponent( MeshFilter ).mesh = someMesh;
with:
gameObject.GetComponent.< MeshFilter >().mesh = someMesh;