x


'[insert member variable name]' is not a member of 'Object' / 'Component' / 'GameObject'

Hey,

I have a system where three scripts are placed on one parent object and reference each other using a technique like this:

From the first script:

var Character:Component;

function Awake(){
     Character = GetComponent("Saki_Character"); //SakiCharacter is the name of the other script or component in the object.
}

function Update(){
     if (!Character.Loaded) return;
}

From SakiCharacter.js:

var Loaded:int = 0;

//some stuff that requires loading and initialization.

Loaded = 1

This was working fine, until I realized a few things were chugging and decided to optimize based on the instructions in the Performance Optimization guide.

I added the #pragma strict line to the beginning of all the script files, and now I'm getting the error from the title of this post. I declared the variable in the other Component! This also affects functions, arrays, and class instances, not just variables.

It makes sense that with #pragma strict, it wouldn't be able to find added-on members, at least with some modification. But I've tried everything I know and I'm fresh out of ideas.

Any clues on how I can get my own Components' members to be recognized and referenced by code in other Components?

Thanks!

more ▼

asked Oct 17 '10 at 08:08 PM

shionyr gravatar image

shionyr
-2 3 4 4

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

1 answer: sort voted first

Character is a Component because you told it to be; that's not what you want. (Also, variable names should be lowercase, by convention, not uppercase. camelCase is also the standard, not word_wordAfterUnderscore) And don't use quotes in GetComponent; it's slower, unnecessary, and clutter. Finally, using Reset instead of Awake means you don't have to run GetComponent at the start of the game, too.

var character : SakiCharacter;

function Reset() {
    character = GetComponent(SakiCharacter);
}
more ▼

answered Oct 17 '10 at 08:33 PM

Jessy gravatar image

Jessy
15.6k 72 95 196

(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:

x822
x472
x111
x32

asked: Oct 17 '10 at 08:08 PM

Seen: 1403 times

Last Updated: Oct 17 '10 at 08:08 PM