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 Marc_0S · Apr 15, 2017 at 12:08 PM · scritping

what am i doing wrong?

i allways get this error when i use this script NullReferenceException: Object reference not set to an instance of an object Ruins.OnTriggerEnter (UnityEngine.Collider box) (at Assets/Scripts/Ruins.cs:24)

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class Ruins : MonoBehaviour { public Text someText; public GameObject AreaEnterSign; public Text someText2;

 void Start()
 {
     someText = GetComponent<Text>();
     AreaEnterSign.gameObject.SetActive(false);
     someText2 = GetComponent<Text>();
 }

 void Update()
 {

 }
 public void OnTriggerEnter(Collider box)
 {
     someText.text = "Ruins Of Suboth";
     AreaEnterSign.gameObject.SetActive(true);
     someText2.text = "Ruins Of Suboth";
 }

 public void OnTriggerExit(Collider box)
 {
     someText2.text = "Hills";
 }

}

can someone help me? i am a very very basic understander of c#

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 Commoble · Apr 15, 2017 at 03:35 PM

This is a good explanation of what a Null Reference Exception is and how to deal with it.

The gist of it is that you're trying to access someObject.someVariableOrFunction when someObject == null, which throws a null reference exception. To fix it, you need to figure out which object field is null when it shouldn't be, and then either prevent it from being null, or handle what happens when it is null.

In your case, it looks like either you don't have a Text component attached to the game object, or you don't have a gameobject linked to your AreaEnterSign field in the inspector. Checking these out should solve your problem.

Side note: If you have two Text components on your object (or any two components of the same type), you won't be able to reach both of them with GetComponent. I suggest linking them in the inspector to make sure the correct text components are assigned to the correct fields.

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 Marc_0S · Apr 16, 2017 at 01:35 PM 0
Share

ok my text is the problem i have checked and it goes null on playmode

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

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

Pass a reference to a button that opened the menu this script is on 0 Answers

How to get component value without using GetComponent() and Update()/FixedUpdate()? 1 Answer

script delay ("on mouseclick") 0 Answers

Using spawners script variable to set relevant speed of an Enemy... Im bewildered 0 Answers

Script to make specific parts of my object bright ? 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