Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 MrBio · Aug 04, 2015 at 08:21 PM · timereferencenulltime.deltatime

Null Reference Exception - Time.deltatime problem

I'm new to unity and I'm in need of help with javascript. Everytime i use in my code Time.deltatime i get a following error:

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) DestroyAfterTimeScript.Update () (at Assets/Scripts/DestroyAfterTimeScript.js:12)

From my understanding of this error i tried to access a reference variable that isn't referencing any object. Yet I stumble upon this error every time i use Time.deltatime in my code, which should work just fine, since i'm referring to a time function. Or maybe I'm wrong, and the problem is much more simple, but since I get this error only when using Time.deltatime, i can't figure out what I'm doing wrong.

The script isn't named "Time", or anything like this. (I red about similar problem, where the solution was to just change the name of the script from "Time" to something else, but it's not the case since my script is named "DestroyAfterTimeScript")

This code is supposed to destroy the object after a certain number of seconds, with a little bit of randomization. So, here it is:

 var destroyAfterTime : float = 10;
 var destroyAfterTimeRandom : float = 0;
 @HideInInspector
 var countToTime : float;
 
 function Awake () {
     destroyAfterTime += Random.value * destroyAfterTimeRandom;
 }
 
 function Update () {
 
     countToTime += Time.deltatime;
     if (countToTime >= destroyAfterTime)
     {
                 Destroy(gameObject);
     }
 }
 

Error points me to the line 12:

     countToTime += Time.deltatime;

Any help would be very appreciated.

Oh, and by the way I'm following ETeeski tutorials, there you can probably find more details of the code i'm trying to get to work. He doesn't seem to have any problems, and his bulletholes disappear just fine. I copied every line of his code, and still it's not working.

Link to the tutorials: https://www.youtube.com/watch?v=ei635F6xeP8&list=PL7AE076AFAFD3C305∈dex=14

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
1
Best Answer

Answer by Jessespike · Aug 04, 2015 at 08:44 PM

Time.deltaTime

Note that the "T" is capitalized in deltaTime

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 MrBio · Aug 04, 2015 at 09:53 PM 0
Share

Thank you so much man! I was trying to figure it out for days, and I haven't thought even for a second the answer could be that simple. You're tha real $$anonymous$$VP! Sorry for my over enthusiasm, but it was my first big headache over an incorrect code and you just randomly appeared and solved it. Good luck in your life and whatever you are doing!

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

2 People are following this question.

avatar image avatar image

Related Questions

while coroutine not ending correctly using unityscript 1 Answer

Time.deltaTime is 0 after LoadLevel 1 Answer

Null Reference Problem Code+pic (SOLVED) 2 Answers

ScriptableObject resets on Play 0 Answers

How can the animation of time bar become smoother? 1 Answer


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