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 Jamar0324 · Jul 08, 2013 at 04:10 PM · androidjavascript#pragma strictdynamic typing

'GetComponent' is not a member of 'Object'.

I know I need to force cast this line but don't know how

 for ( var checkDoor : GameObject in cells[i].GetComponent(AIPathCellScript).doors)
 
 // have tried this 
 for ( var checkDoor : GameObject in (cells[i].GetComponent(AIPathCellScript)as AIPathCellScript).doors)
 
 // and also this 
 for ( var checkDoor : GameObject in cells[i].GetComponent.<AIPathCellScript>().doors)

and still coming out with the same error, Any Help would be greatly apperciated.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by aldonaletto · Jul 08, 2013 at 04:38 PM

What's cells ? From the error message, I suspect that it's an Array (Array class, not builtin array): Array elements are defined as Object, the variant type that can hold values of any type. If this is the case, you should first get the cells element in a GameObject variable (supposing that each cell element is a GameObject), get the doors array reference and then enter the loop:

 var cell: GameObject = cells[i];
 var doors: GameObject[] = cell.GetComponent(AIPathCellScript).doors;
 for (var checkDoor: GameObject in doors){
     //
 }
Comment
Add comment · Show 3 · 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 Jamar0324 · Jul 08, 2013 at 05:08 PM 0
Share

yes Cells is a Array class and Doors is another Array class in another script, and I'm trying to access that array with the for loop when I enter the code Aldonaletto gave meits giving me this error $$anonymous$$ identifier: 'cells'.

avatar image aldonaletto · Jul 08, 2013 at 05:28 PM 0
Share

cells should be defined in your script - check spelling. Anyway, if doors is another Array, the assignment to a GameObject array will fail - declare doors as an Array:

 var cell: GameObject = cells[i];
 var doors: Array = cell.GetComponent(AIPathCellScript).doors;
 for (var checkDoor: GameObject in doors){
     //
 }

You'll get compiler warnings about Implicit downcast from 'Object' to 'UnityEngine.GameObject', but the code should work.

avatar image Jamar0324 · Jul 08, 2013 at 05:56 PM 0
Share

Thank you its working now, Thanks for the fast reply as well.

avatar image
0

Answer by asduffo · Jul 08, 2013 at 04:37 PM

Answer from a noob: is the content of the cells array a list of prefabs? If so, of course it happens because GetComponent is avaiabile only for GameObject and Component instances. Try to initiazlize the objects as GameObject using the method

 list[i] = Initialize(Object object, Vector3 position, Quaternion.identity);

and then use GetComponent. It should work

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

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Building on android. 1 Answer

Error importing asset from google poly api in android build unity 0 Answers

Error BCW0015 and BCW0023 but they both work, how to solve it? 1 Answer

Converting screen coordinates to world coordinates 1 Answer

Executing Code Once Per Touch 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