Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by shionyr · Oct 17, 2010 at 08:08 PM · variableoptimizationbce0019pragma

'[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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

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); }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

how can I create a variable to refer to any gameObject script with pragma strict 1 Answer

Transform handle for prefab and getting to a prefab script variable? 1 Answer

Optimizing OnGUI 1 Answer

What more should I be caching within my scripts? 3 Answers

Using static typing for a Component 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges