x


I get an error on build but not when I run the game in the Editor. iPhone.

Hi. I am working on a game and everything runs fine when I test it using Unity Remote. I can play the game while while controlling it with the iPhone and watch it run in the editor.

But when I try to build the game I get the following error: Error building Player because scripts had compiler errors

The Error it is refearing to is the following: Assets/MyScripts/SpawnScript.js(42,73): BCE0019: 'NewParent' is not a member of 'UnityEngine.Component'.

Now I understand where the error is pointing me. What I dont understand is why does it run fine when I test it in the editor using the play button.

The following script is what the error is referring to:

if(hit.transform.gameObject.name == ThisTransform)
            {
                var EntryScript = EntryGameObject.GetComponent(EntryScript);
                if(EntryScript.NewParent.childCount == 0)
                {
                    var NewParent : Transform = EntryScript.NewParent;
                    CloneBox.transform.parent = NewParent;
                    filled = false;
                    print(hit.transform.gameObject.name);
                }
            }

What I am doing here is assigning a new parent to a instantiated clone. This has to be dynamic because the parent often changes. And who the new parent should be is determined by the EntryScript on EntryGameObject. Again, this all works perfectly fine when tested in the editor.

more ▼

asked Jan 01 '11 at 03:54 PM

Anxowtf gravatar image

Anxowtf
1.6k 22 27 37

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

When using Javascript on iPhone/Android, put "#pragma strict" at the top of all your scripts, and fix any resulting dynamic typing issues. GetComponent returns Component, so you have to cast that as the correct type instead of relying on dynamic typing. Using generics is usually the easiest way (and also you should use the convention of lowercase for variable names, which makes things less confusing):

var entryScript = entryGameObject.GetComponent.<EntryScript>();
more ▼

answered Jan 01 '11 at 04:00 PM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

Thank you.

I am sure what you said made sense but I did not understand most of it. The #pragma strict is interesting and I get that, I saw the syntax changes in your script exsample and it worked. I did not get your explination but I am greatful for your help.

The #pragma strict I had to turn back off after this fix because it gave me an error on my Instantiate. Can not convert object to game object. but when I turn strict off it will build.

Jan 01 '11 at 04:18 PM Anxowtf
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x123
x111
x44

asked: Jan 01 '11 at 03:54 PM

Seen: 759 times

Last Updated: Jan 01 '11 at 03:54 PM