Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by KnightRiderGuy · Dec 03, 2015 at 04:45 PM · c#error messagereferencenon-staticmember

object reference is required to access non-static member - What does this mean?

 if (dev05State == true){
                 Sending.sendBlue (); //Surveillance Mode
                 SurveillanceModeManager.TogglePlay ();

I'm trying to call another script to have it activate something but I get this error message:

 Assets/Scripts/CountdownTimerManager.cs(124,57): error CS0120: An object reference is required to access non-static member `SurveillanceModeManager.TogglePlay()'
 

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 Jessespike · Dec 03, 2015 at 05:48 PM 1
Share

as meat5000 explained. `Surveillance$$anonymous$$ode$$anonymous$$anager.TogglePlay()' will only work if it's a public static function. If it's not, then you need an instance of Surveillance$$anonymous$$ode$$anonymous$$anager. For example:

 Surveillance$$anonymous$$ode$$anonymous$$anager smm = FindObjectOfType<Surveillance$$anonymous$$ode$$anonymous$$anager>();
 smm.TogglePlay();

smm is the instance of Surveillance$$anonymous$$ode$$anonymous$$anager

avatar image KnightRiderGuy Jessespike · Dec 03, 2015 at 07:08 PM 0
Share

Thanks @Jessespike That was very helpful to have a code sample. I added in the extra line for the animation and it works perfectly.... not sure if it would work across scene changes as I ended up moving this panel into the main scene and just making it a slide in screen but the scripts at least talk to each other now. $$anonymous$$uch $$anonymous$$UCH thanks for that :)

 if (dev05State == true){
                 Sending.sendBlue (); //Surveillance $$anonymous$$ode
                 Surveillance$$anonymous$$ode$$anonymous$$anager smm = FindObjectOfType<Surveillance$$anonymous$$ode$$anonymous$$anager>();
                 smm.TogglePlay();
                 smm.PlayLEDLightsAnimation();
             }

 

1 Reply

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

Answer by meat5000 · Dec 03, 2015 at 05:31 PM

You attempt to make a call to an object which has not been referenced. This only works with static members. If something is static it is Unique and can be accessed from anywhere. A non-static member requires you to tell the compiler where/what it is.

You already know this :D

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

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

An object reference is required to access non-static member 1 Answer

Instatiated object not being referenced in Start function? 2 Answers

Getting Int value from script to other script 2 Answers

Cannot implicitly convert type `string' to `int' 0 Answers

Fix? The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. 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