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 EClancy · Oct 20, 2014 at 12:13 AM · javascriptgetcomponentparentrendererchildren

GetComponent searches an objects child instead of the object

First, I have a gameobject that is named "Player1". It has a child, specifically used for checking things that touch it's feet.

For some reason, Unity is complaining when I try to set Player1's SpriteRenderer, saying that feetCheck has no SpriteRenderer. It seems that Unity thinks basePlayer1 is feet check, even though it's properly assigned. Could someone explain what's going on?

alt text

Here is my Player1:

alt text

The piece of code that is breaking is here:

alt text

And here is the error:

alt text

Here is the assignment in the inspector, showing that basePlayer1 is NOT feet check, and is assigned appropriately:

alt text

Finally, this is when I Debug.Log basePlayer1. Clearly, Player1 is the object, and yet when I print the object, it thinks it is feetcheck.

alt text

Any advice is appreciated :)

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

Answer by Bunny83 · Oct 20, 2014 at 12:31 AM

"Could someone explain what's going on?"

Sure, you probably did something wrong ;)

Unity never "thinks" anything. If basePlayer1 references the FeetCheck Gamobject when you use it (either your getcomponent line or the Devug.Log line) then it does reference this object. That's a matter of fact, no guessing needed. If it points to you player object at edit time but to something else at runtime, you probably set it to something else somewhere in your code.

You only showed some fragments, but i guess the script you're talking about is attached to the FeetCheck object, right? Also is your player object a prefab? Where have you assigned which "Player" to which variable on which object? It looks like you tried to hide as much as possible, however that doesn't help to even understand half of your actual setup.

Comment
Add comment · Show 2 · 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 EClancy · Oct 20, 2014 at 04:36 PM 0
Share

Unity has biased opinions on what Player1 should be, and I'm merely trying to convince Unity to see things my way. All of this "logic" stuff you're throwing at me is confusing.

The script I'm talking about is not attached to FeetCheck, it is a script in an empty gameObject all on it's own to handle global variables.

$$anonymous$$y player object is a prefab, yes.

The player is assigned in the global handler script, not with code but with Drag n' Drop in the inspector. The second to last, and last picture shows this, on the right.

I'm not sure what you mean by trying to hide as much as possible, I'm completely willing to post more information/code. I posted everything that I thought was relevant, which, since I'm asking the question, I know doesn't help much :)

avatar image EClancy · Oct 20, 2014 at 06:04 PM 0
Share

Problem was solved, posted as another answer.

avatar image
0

Answer by EClancy · Oct 20, 2014 at 06:16 PM

Figured this out on my own, but the answer is less glamorous than I would have thought. Upon exiting Unity last night, it crashed. Reopening it this morning caused another crash, and finally when it was working again, my variables were not properly assigned in the inspector. I reassigned them, and viola, it was working.

Turns out, the whole time Unity was just bugging and needed to get a few crashes out of it's system. Happens to the best of us.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

check if children are visible, if not destroy parent? 1 Answer

how to put the objects together (javascript) 1 Answer

Deactivate Specific Children In Partent 1 Answer

Create multiple instances of an object 2 Answers

Update Parent/ Children From Script? 2 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