Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by thecakeisalie · Sep 05, 2016 at 04:17 AM · errorgameobjectcomponent

Can't reference script of parent

Hi guys,

I want to call a function in the parent but I get a 'The name does not exist in the current context' error.

EDIT: Error message

 Assets/Scripts/LaneDetection.cs(14,74): error CS0246: The type or namespace name `Platformer2DUserControl' could not be found. 

EDIT2: corrected

 transform.parent.gameObject.GetComponent<Platformer2DUserControl>()

Tried several variations but nothing works.

Nothing found during research.

Please help me.

Comment
Add comment · Show 4
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 Norfinity · Sep 05, 2016 at 08:53 AM 0
Share

Does gameObject.GetComponentInParent<Platfomer2DUserControl>() work?

avatar image thecakeisalie Norfinity · Sep 05, 2016 at 03:38 PM 0
Share

No, doesn't work.

avatar image doublemax Norfinity · Sep 05, 2016 at 04:01 PM 1
Share

$$anonymous$$aybe just a typo, missing 'r'? "Platfo(r)mer2DUserControl"

avatar image Bunny83 · Sep 05, 2016 at 04:43 PM 0
Share

doublemax and Glurth are most likely right. Next time when you post a question about a compiler error include the whole error message and the actual wording.

You can select and copy text directly from the detail area of the console window in Unity. No need to type the error manually.

2 Replies

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

Answer by Glurth · Sep 05, 2016 at 04:11 PM

'The name does not exist in the current context'

The error means that one of the identifiers (names) in the line either has not been defined, or is "out of scope". I would suspect Platfomer2DUserControl is the culprit identifier (as doublemax mentioned), because I recognize the others. I don't remember the last time I actually TYPED in a class name, far too error prone (without visual studio intellisence). I usual copy and paste class and variable names, to avoid just such errors.

Such an issue can also occur, even with properly spelled class names, if the class name in questions is "out of scope". Usually this has to do with "namespaces", but unless you have defined your own, this is probably not the issue in this case. If you HAVE defined your own namespace, and within it's scope is Platfomer2DUserControl: THEN you will need to include a "using" command at the top of your script specifying that namespace. This command will put that namespace "in scope" for that file.

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 thecakeisalie · Sep 05, 2016 at 05:38 PM 0
Share

The spelling was my mistake, sorry. Nonetheless it won't autocomplete my script name. Added error message in question. Please explain the namespace topic I think that's what I need.

avatar image thecakeisalie thecakeisalie · Sep 05, 2016 at 07:16 PM 0
Share

Combined solution in the post below.

avatar image Glurth thecakeisalie · Sep 05, 2016 at 10:25 PM 0
Share

I have found I need to recompile the script successfully, AFTER I add "`using someNamespace;`" to the top of the file: at that point intellisence can finally see into the namespace, and make suggestions.

avatar image
0

Answer by thecakeisalie · Sep 05, 2016 at 07:15 PM

Thanks to @Glurth, I added the same namespace and took @BeckStarDEs solution and now it works.

Thanks!!

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

7 People are following this question.

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

Related Questions

NullPointException Object not found, caused by a variable not accepting value? 0 Answers

Array index out of range(C#) 1 Answer

Not all code paths return a value 1 Answer

Object reference; sometimes works but sometimes doesn't??? 2 Answers

Setting EventTrigger in Unity with JavaScript 0 Answers


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