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 darak · Mar 12, 2012 at 09:36 PM · gameobjectgetcomponentboo

Trouble accessing scripts (Boo)

Hello,

I'm currently having trouble using the GetComponent function to access scripts. I currently have three scripts. One called ForcesUmbrella attached to an object in the scene, another called CameraInfo attached to the Main Camera and the final one called GetInfo attached to both the camera and the game object.

What I am trying to do is access the GetPosition() function in ForcesUmbrella from CameraInfo through GetInfo but I keep getting a "NullReferenceException: Object reference not set to an instance of an object" error so I must be doing something wrong.

If somebody can point me in the right direction I would be more than grateful.

Thank you and here are the scripts:

 #### ForcesUmbrella ####
 import UnityEngine
 
 class ForcesUmbrella (MonoBehaviour):
     
     def Start ():
         pass
     
     def Update ():
         pass
     
     def GetPosition():
         Debug.Log('It works')
 #####################
 #### CameraInfo ####
 import UnityEngine
 
 class CameraInfo (MonoBehaviour):
     
     public umbInfo as GetInfo
         
     def Start ():
         umbInfo = GetComponent[of GetInfo]()
     
     def Update ():
         umbInfo.GetUmbrella()
 ##################
 #### GetInfo ####
 import UnityEngine
 
 class GetInfo (MonoBehaviour):
     
     public umbInfo as ForcesUmbrella
 
     def Start ():
         umbInfo = GetComponent[of ForcesUmbrella]()
     
     def Update ():
         pass
     
     def GetUmbrella():
         umbInfo.GetPosition()
 ##############
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
0

Answer by skalev · Mar 13, 2012 at 12:15 AM

I don't use boo, but it seems like your problem is that you are trying to get the component.

So, when you call GetComponent, you will only get the component attached to the current GameObject.

What you want to do is find the correct GameObject first:

http://unity3d.com/support/documentation/ScriptReference/GameObject.Find.html

and then get the script you need from that compnent using GetComponent.

Plus, this seems like a very inefficient way of doing things, why do you need 3 scripts to connect to one another?

Comment
Add comment · Show 1 · 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 darak · Mar 13, 2012 at 10:01 AM 0
Share

Thank you skalev for the reply.

Indeed the problem was that I was not defining the correct GameObject before I searched for the script I wanted to access.

As for the efficiency I see what you mean. Going through the 'GetInfo' detour is unnecessary. Here I was just testing out accessing a GameObject's script from another GameObject. I thought that having a separate script 'GetInfo' that can be accessed by all objects to get other object's info would be good. But after sleeping on it I don't think so anymore.

Thanks again

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GetComponent not Returning 1 Answer

gameObject.GetComponent("Script").enabled = true not working 5 Answers

C# GetComponent Issue 2 Answers

script GetComponent, nullReference error 1 Answer

Accessing script variables of instantiaded prefab 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