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 sacajawhoohoo · Jun 12, 2015 at 04:08 AM · errornullreferenceexceptionnot workingreferencesetactive

SetActive is giving me a lot of issues

So Ive used GameObject.active = true for quite a long time, however I am trying to get to learn SetActive as its updated and preferred, however I have kindof an issue when I try to use it, here is the script var obj1 : GameObject[]; function Start() { obj1 = GameObject.FindGameObjectsWithTag("TheObj1"); if (PlayerPrefs.GetInt("ObjOn")==1) { obj1.GameObject.SetActive (true); } else if (PlayerPrefs.GetInt("ObjOn")==0) { obj1.GameObject.SetActive (false); } }

and the error is: NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args) UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType) ObjOnJV.Start () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/Camera/ObjOnJV.js:9)

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 Hrungdak · Jun 12, 2015 at 04:36 AM 1
Share

c# insists on writing Gameobject like this:

 obj1.gameObject.SetActive (true)

(lower case at the beginning). I don't know if US has the same limitation.

2 Replies

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

Answer by Lachee1 · Jun 12, 2015 at 05:49 AM

You object is null. The game cannot find any objects with the tag "TheObj1". Make sure the object exists at the beginning of the game and it is tagged correctly. Maybe manually assign the object in the inspector instead of relying on the FindObjectWithTag function.

--edit--

You are also calling SetActive from obj1.GameObject, so you are getting the static class GameObject. You want to write it in lower case, like obj1.gameObject.SetActive(true);

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 sacajawhoohoo · Jun 13, 2015 at 12:00 AM 0
Share

alright, thank you

avatar image sacajawhoohoo · Jun 15, 2015 at 01:28 AM 0
Share

I seem to be having a new error however, I changed it to both gameObject, and removed the FindObject function and just manually did it, however now i am receiving this error:

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cache$$anonymous$$eyName, System.Type[] cache$$anonymous$$eyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cache$$anonymous$$eyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args) UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType) ObjOnJV.Start () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/Camera/ObjOnJV.js:7)

avatar image
1

Answer by superbsumit · Jun 12, 2015 at 05:56 AM

Your implementation is wrong. Your 'obj1 ' variable is an array of GameObjects, so doing this ' obj1.GameObject.SetActive (true);' won't work. It's not a valid line of code and it will not compile at all. You should SetActive for an 'array' of objects as this:

 for(var i : int = 0; i < obj1.Length; i++){
  obj1[i].gameObject.SetActive (true);
 }

Also, your 'NullReferenceException' error is coming up from somewhere else, cuz the above code will give the compilation error first.

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 sacajawhoohoo · Jun 13, 2015 at 12:00 AM 0
Share

Ill make sure to try this ins$$anonymous$$d

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

24 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 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

NullReferenceException 3 Answers

How to call a function from another script - getting error "Object reference not set to an instance of an object" 5 Answers

NullReferenceException Error 6 Answers

GameObject[] Issues 1 Answer

NullReferenceException: Object reference not set to an instance of an object 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