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 /
  • Help Room /
avatar image
0
Question by Frozenmidgets · Mar 10, 2016 at 01:08 AM · scripting problemscript errorsingletondatatype

Singleton Problem

I'm new to coding in unity and wanted to transfer data from one script to another. I followed the tutorial i learned this from step by step(to the best of my knowledge) and I don't get any compiler errors but when I try to transfer the data i get this error:

NullReferenceException: Object reference not set to an instance of an object Button.jar () (at Assets/Scripts/Button.cs:8) UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:144) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:621) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:756) UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53) UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44) UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52) UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269) UnityEngine.EventSystems.EventSystem:Update()

Here are my Scripts

This i the script i want the data to be stored on:

 using UnityEngine;
 using System.Collections;
 
 public class BodySpawner : MonoBehaviour {
     public static BodySpawner control;
 
     public int money;
     public int rate;
 }

This is the script I want to modify the data:

 using UnityEngine;
 using System.Collections;
 
 public class Button : MonoBehaviour {
     
     public void jar ()
     {
         Debug.Log(BodySpawner.control.money);
     }
 }
 

Comment
Add comment · Show 4
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 saud_ahmed020 · Mar 10, 2016 at 06:33 AM 1
Share

@$$anonymous$$enmidgets

  using UnityEngine;
   using System.Collections;
   
   public class BodySpawner : $$anonymous$$onoBehaviour {
       private static BodySpawner control;
   
       public int money;
       public int rate;
  
       void Start()
      {
          money = 0;
          rate = 0;
      }
      public static BodySpawner SharedInstance()
     {
         return control;
     }
   }
  
   using UnityEngine;
   using System.Collections;
   
   public class $$anonymous$$yButton : $$anonymous$$onoBehaviour {
       
       public void jar ()
       {
           Debug.Log(BodySpawner.SharedInstance().money);
       }
   }

   
avatar image Frozenmidgets · Mar 10, 2016 at 03:11 PM 0
Share

@saud_ahmed020 im sorry but that didnt work, i got the same error.

avatar image saud_ahmed020 Frozenmidgets · Mar 11, 2016 at 05:42 AM 0
Share

@$$anonymous$$enmidgets You are not allowed to make a class with defined keywords unless you have different namespace. So, just change the name of class "Button" to something other like "$$anonymous$$yButtons".

avatar image Frozenmidgets · Mar 11, 2016 at 01:31 PM 0
Share

@saud_ahmed020 Oh ok makes sense. Thank you! :)

0 Replies

· Add your reply
  • Sort: 

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

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

How do I use Singleton Design pattern in unity3d C# 2 Answers

How do I access Singleton Pattern Script in Unity3d C# 1 Answer

Why do I keep getting this error? 1 Answer

Please Help With Script 1 Answer

Making a game where objects need to be shot off of a surface. level complete when all objects are shot off. difficulty in scripting for level completion. 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