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 MikezNesh · Jul 25, 2010 at 12:20 AM · errorgetcomponent

An odd GetComponent error...

I am getting a 'waypoint is not a member of 'UnityEngine.Component' error. And I don't know what is wrong...

CODE WAS HERE.

By the way, I did set up another script called waypoinSoldier and variable waypoint(if you were wondering)

Please tell me what I am doing wrong. Thanks.

EDIT:

CODE WAS HERE.

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
3
Best Answer

Answer by Mike 3 · Jul 25, 2010 at 01:24 AM

If you're on the iPhone, it's because it doesn't support dynamic typing, so you have to force the type manually

Alternatively, you could have #pragma strict at the top of your file if you're not on iPhone - it does the exact same thing

var soldier : waypointSoldier = instantiated.GetComponent(waypointSoldier);
soldier.waypoint = hit1.collider;

Note: You should get into the habit of doing that anyway, it's quite a bit slower to do it the way you're trying

Edit:

change

var instantiated : Rigidbody = Instantiate (unit, transform.position, transform.rotation); 

to

var instantiated : waypointSoldier = Instantiate (unit, transform.position, transform.rotation);

That'll be why it wasnt working with transform either (though using the script type is much better)

Comment
Add comment · Show 26 · 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
avatar image Mike 3 · Jul 25, 2010 at 10:34 PM 1
Share

Can't see anything wrong at first glance, only thing i can think of is that the script isn't on the root object or something along those lines. is it throwing any runtime errors? Other than that, no clue, try debugging what's null and what isn't

avatar image Mike 3 · Jul 26, 2010 at 12:54 AM 1
Share

Probably that the script isn't on the root of the object. try GetComponentInChildren ins$$anonymous$$d

avatar image Mike 3 · Jul 26, 2010 at 08:25 AM 1
Share

if it were me, i'd change the type for unit to be waypointSoldier (which will mean readding the prefab). Then you don't even need to do getcomponent, it'll be the right object type, and you know for sure your object has the script on

avatar image Mike 3 · Jul 26, 2010 at 05:08 PM 1
Share

var unit : Transform; becomes var unit : soldierWaypoint; - after which you $$anonymous$$UST reselect the prefab in the inspector

avatar image Mike 3 · Jul 26, 2010 at 06:36 PM 1
Share

waypointSoldier

Show more comments

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

1 Person is following this question.

avatar image

Related Questions

Player Prefs, Adding Two Variables 1 Answer

C# GetComponent()... Not finding script problem. 1 Answer

Instantiate Prefabs. Errors. 2 Answers

error CS1525: Unexpected symbol `)' 1 Answer

Calling a function from another script issue 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