- Home /
'[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!
Answer by Jessy · Oct 17, 2010 at 08:33 PM
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); }
Your answer
