Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 CameronSanders · Feb 10, 2014 at 03:21 AM · javascript

Why am I getting a "NullReferenceException" for a Instantiate line?

I've had this weird problem I've been trying to figure out for a few hours, I gave up and was wondering if you guys could help. On this line "`var coconut = Instantiate (coconutprefab, Vector3(transform.localPosition.x, transform.position.y + 2.5, transform.localPositionn.z - 2.0), Quaternion.identity);`" I get a NullReferenceException error. However if i change "`Vector3("stuff")`" to "`Vector3(0,0,0)`" it works. I have made sure all the variables have been connected to objects. This was working fine this morning, I don't know what happened.

 function sinstunned() {
 stuncooldown = true;
 if (coconutcount.coconutsCollected > 0 && spawnerwait == false) {
 spawnerwait = true;
 coconutcount.coconutsCollected = coconutcount.coconutsCollected - 1;
 var coconut = Instantiate (coconutprefab, Vector3(player.transform.localPosition.x, player.transform.position.y + 2.5, player.transform.localPositionn.z - 2.0), Quaternion.Inverse(coconutprefab.transform.rotation));
 coconut.transform.rotation = Quaternion.Inverse(player.transform.rotation);
 coconut.GetComponent(CollectCoconut).player = cocoCharController;
 coconut.animation["ArmatureAction"].speed = -1;
 coconut.animation["ArmatureAction"].time = coconut.animation["ArmatureAction"].length;
 coconut.animation.Play("ArmatureAction");
 }
 walkscript.enabled = false;
 thirdcharmotor.enabled = false;
 player.animation.Play("OrcStun2");
 yield WaitForSeconds (2.0);
 walkscript.enabled = true;
 thirdcharmotor.enabled = true;
 OrcStun = false;
 
 yield WaitForSeconds (1.0);
 stuncooldown = false;
 spawnerwait = false;
 }
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 robertbu · Feb 10, 2014 at 04:03 AM 0
Share

The most likely issue is that 'coconutprefab' has not be initialized. You don't show the code for initialization, so we cannot check that part of the code. If you are initializing it through drag and drop in the Inspector, and if you verify the value is set in the Inspector, check to make sure you don't have a second copy of the script attached elsewhere.

avatar image CameronSanders · Feb 10, 2014 at 04:26 AM 0
Share

Yeah I used drag and drop, I made sure it was in there. Here is the full script:

 var dead = false;
 var player : GameObject;
 var shark : GameObject;
 var killcam : Camera;
 var thirdPCam : Camera;
 var FirstPCam : Camera;
 var OrcStun = false;
 
 var deadgui : GUIText;
 var mousescript : $$anonymous$$ouseLookFpp;
 var thirdPCamscript : ThirdPersonCamera;
 var charmotor : Character$$anonymous$$otor;
 var thirdcharmotor : ThirdPersonController;
 var fpsscript : FPSInputController;
 var CameraSwap : CameraSwap;
 var walkscript : Walk;
 var stuncooldown = false;
 var coconutcount : TotalCoconuts;
 var coconutprefab : GameObject;
 var cocoCharController : CharacterController;
 var spawnerwait = false;
 
 
 function Update () {
 
 
 if (player.transform.position.y <= 15) {
     dead = true;
     shark.transform.position.x = player.transform.position.x;
     shark.transform.position.z = player.transform.position.z;
     shark.transform.position.y = 6;
     player.active = false;
     mousescript.enabled = false;
     killcam.enabled = true;
     thirdPCam.enabled = false;
     FirstPCam.enabled = false;
     thirdPCamscript.enabled = false;
     charmotor.enabled = false;
     thirdcharmotor.enabled = false;
     fpsscript.enabled = false;
     CameraSwap.enabled = false;
     deadgui.enabled = true;
 }
 
 if (OrcStun == true) {
 sinstunned();
 
 }
 
 }
 
 
 function sinstunned() {
 stuncooldown = true;
 if (coconutcount.coconutsCollected > 0 && spawnerwait == false) {
 spawnerwait = true;
 coconutcount.coconutsCollected = coconutcount.coconutsCollected - 1;
 var coconut = Instantiate (coconutprefab, Vector3(player.transform.localPosition.x, player.transform.position.y + 2.5, player.transform.localPositionn.z - 2.0), Quaternion.Inverse(coconutprefab.transform.rotation));
 coconut.transform.rotation = Quaternion.Inverse(player.transform.rotation);
 coconut.GetComponent(CollectCoconut).player = cocoCharController;
 coconut.animation["ArmatureAction"].speed = -1;
 coconut.animation["ArmatureAction"].time = coconut.animation["ArmatureAction"].length;
 coconut.animation.Play("ArmatureAction");
 }
 walkscript.enabled = false;
 thirdcharmotor.enabled = false;
 player.animation.Play("OrcStun2");
 yield WaitForSeconds (2.0);
 walkscript.enabled = true;
 thirdcharmotor.enabled = true;
 OrcStun = false;
 
 yield WaitForSeconds (1.0);
 stuncooldown = false;
 spawnerwait = false;
 }

1 Reply

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

Answer by getyour411 · Feb 10, 2014 at 04:47 AM

Looks like you misspelled position a few times (positionn)

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 CameronSanders · Feb 10, 2014 at 05:05 AM 0
Share

Wow that's embarrassing. Thanks for picking that up.

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

18 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

Related Questions

Instantiating Particle System and Editing Base Settings 0 Answers

Destroy/Kill AI, Without Errors? 0 Answers

"GameObject.Find();" not working 2 Answers

beginner question- several errors 1 Answer

can't get this right... help please... 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