• 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 stark89 · Sep 19, 2012 at 10:34 AM · iphonenull referencegameobject.active

Issue in gameObject.SetActiveRecursively

Hi,

I am enabling a series of game objects with gameObject.SetActiveRecursively(true);

its something like :

 void Activate()
 {
     thisGameObject.SetActiveRecursively(true);
 
     totalCoins.DisplayTotalCoins = GlobalClass.TotalCoins.ToString();        
 }    

here totalCoins is a component of a child of thisGameObject. I get a null reference when i try to acces totalCoins.Text

Plss help

Thanks in advance

Comment
Add comment · Show 2
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 john-essy · Sep 19, 2012 at 11:08 AM 0
Share

What is the null reference?

avatar image stark89 · Sep 19, 2012 at 11:21 AM 0
Share

its states that instance of totalCoins is not found

NullReferenceException: Object reference not set to an instance of an object

3 Replies

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

Answer by Michael Covert · Sep 19, 2012 at 05:22 PM

It's telling you what's wrong - "NullReferenceException: Object reference not set to an instance of an object". This doesn't mean your thing is inactive; it means you've never set it, or you've destroyed it. You'll need to make a public variable and assign it via the inspector, or use some code to find the particular object you're looking for.

If you do it via code, GameObject.Find() can get you the object, and calling get component on the result can get you your particular script.

If you're already trying to do this, note that GameObject.Find() only finds active objects - so you'll need to call it after turning the object on.

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 stark89 · Sep 20, 2012 at 12:30 PM 0
Share

yeah, thanks a ton.... assigning it to a public variable and activating it worked......

avatar image
0

Answer by shaico · Sep 19, 2012 at 04:18 PM

maybe you get null reference because you disable this object then try to call then next function but the object is disabled so u get null. try calling display total coins and after it disable the object.

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
avatar image
0

Answer by john-essy · Sep 19, 2012 at 11:08 AM

ah i think i know where your problem is it should be this.gameObject.SetActiveRecursively(true)

Comment
Add comment · Show 4 · 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 stark89 · Sep 19, 2012 at 11:22 AM 0
Share

nope :( tried that...

avatar image john-essy · Sep 19, 2012 at 01:06 PM 0
Share

Do you have a reference to that object because it doesnt seem like thier is a reference to the coins.

avatar image stark89 · Sep 19, 2012 at 03:20 PM 0
Share

yeah, I am calling that object from outside this function, which works just fine.

I am not sure of this but does gameobject.SetRecursivelyActive()takes more than a frame to complete?

avatar image john-essy · Sep 19, 2012 at 05:09 PM 0
Share

It may take longer than a frame i am not sure. But i have never had this problem before. and you do have it like this.blah blah and with a lower case g

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

iAd in Unity 1.7 1 Answer

How to detect Game Object is touched in Unity iPhone? 1 Answer

Where to start? 3 Answers

Unity3D 3.X generates a iPhone_target2AppDelegate? Use? 0 Answers

Unity iPhone 2D Left Right movement 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