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 /
avatar image
0
Question by Dillon · Oct 02, 2011 at 04:38 AM · functionlinking

Problems accessing a function

Okay, so I know people ask this a lot but this is a specific question (I already basically know how to do it)

I'm trying to access a script inside a particular object and call a function in it, I essentially just copied the code from unity script reference that says how to do that.

 var ConPlat = GameObject.FindWithTag("AntiCore");
     ConPlat.GetComponent(CollideCounter).Damage(MissDamage);

But it keeps saying that on that second line that "object reference not set to an instance of an object". I know it's not talking about MissDamage because that's an int, and there is a script called CollideCounter, and the object that has that script does have a "Core" tag. So I'm confused.

Comment
Add comment · Show 1
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 syclamoth · Oct 02, 2011 at 05:55 AM 0
Share

Try splitting it up, like so, and putting Debug.Log inbetween every step. That way, it'll tell you where it's going wrong!

 var ConPlat : GameObject = GameObject.FindWithTag("AntiCore");
 Debug.Log(ConPlat);
 var collideCount : CollideCounter = ConPlat.GetComponent(CollideCounter);
 Debug.Log(ConPlat);
 collideCount.Damage($$anonymous$$issDamage);

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Catlard · Oct 02, 2011 at 06:03 AM

I see two possible places for an error:

1) You've said it had a "Core" tag, but does it have an "AntiCore" tag like your code asks for?

2) GameObject.FindWithTag returns ONE gameobject, but I believe it's a random object with that tag. Maybe it's not the gameobject with the "AntiCore" tag that you're looking for--and maybe the object that it's finding doesn't have the CollideCounter script on it. You know?

Comment
Add comment · Show 6 · 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 syclamoth · Oct 02, 2011 at 06:11 AM 0
Share

Yes, it's the 'first' object with that tag... whatever that happens to mean at the time.

avatar image syclamoth · Oct 02, 2011 at 06:12 AM 0
Share

If there's a lot of objects with that tag, do you want to iterate through them? Apply the same logic to every one?

avatar image Catlard · Oct 02, 2011 at 06:44 AM 0
Share

Behold, the sound of silence :)

avatar image Dillon · Oct 03, 2011 at 05:42 AM 0
Share

It has a Core and AntiCore tag, and there's only one object for each tag. Each object has the CollideCounter script on it, as I said. Any other ideas?

avatar image syclamoth · Oct 03, 2011 at 06:20 AM 0
Share

Have you tried what I suggested in my comment? It could shed some light on your problem.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Connecting scenes 3 Answers

Calling a variable from one script to another 1 Answer

Is there any way to link an image object to another game object's component? 0 Answers

function for colliding without using rigid body's? 1 Answer

variable = true from another 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