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 NinjaRubberBand · Jan 10, 2016 at 06:36 PM · rotationforce

Object reference not set as an instant of an object

This is what it says:

NullReferenceException: Object reference not set to an instance of an object carSpawner.SpawnCar () (at Assets/carSpawner.js:28) carSpawner.FixedUpdate () (at Assets/carSpawner.js:21)

Here is my script: #pragma strict var SpawnChooser; var startTime : float = 3f; //give you a delay at the begining of the game. var timeLeft : float; var timeBetweenSpawns : float = 1.5f; //if you want to speed up the spawn rate, use this. var spawnLocation : GameObject[]; var objectToSpawn : Transform; function Awake(){ spawnLocation = new GameObject[4];// asuming that we only have 5 lanes. timeLeft = startTime; } function FixedUpdate(){ //I think the biggest problem is the lack of a timer, between spawns. if(timeLeft > 0){ %|1144764443_15|% }else if(timeLeft <= 0){ SpawnCar(); timeLeft =timeBetweenSpawns; } %|-62069431_20|% function SpawnCar(){ %|1422920987_22|% print ("Car spawn"); Instantiate(objectToSpawn,spawnLocation[laneToSpawn].transform.position,Quaternion.identity); }

My obejctToSpawn is a prefab of a car.. I get this error a lot, but it still confuses me..

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 JedBeryll · Jan 10, 2016 at 08:37 PM 1
Share

Please format your script with the 1010 button. I think you didn't assign the "objectToSpawn" which by the way i think should be a gameObject ins$$anonymous$$d of transform.

avatar image DCordoba · Jan 11, 2016 at 01:38 AM 0
Share

as JedBeryll said you can't use intantiate from a transform, you can do two ways to fix this. first change type of the variable objectToSpawn to GameObject, in line 6,

 var objectToSpawn : GameObject;

you will need to pass the entire GameObject to the script. the other way is obtain the GameObject that component is attached, in line 28

 Instantiate(objectToSpawn.gameObject, spawnLocation[laneToSpawn].transform.position, Quaternion.identity);


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

42 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

Related Questions

How to move a force along with an object? 0 Answers

How do I add forward force to an object so that when it rotates, it still goes forward relative to the object, not the world? (picture inside in case I worded it badly) 1 Answer

How do I make AddForce apply force relative to the rotation of another object? 0 Answers

How To Rotate Player with Rotating object 0 Answers

Instant rotation bug when rotating clockwise 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