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 Skullwing · Feb 09, 2013 at 04:36 PM · instantiateobjectreferencenot found

Object reference not set to an instance of an object

Hey, wenn ich versuche meinen Charakter zum schießen zu bringen (Linksklick) kommt diese Fehlermeldung:

NullReferenceException: Object reference not set to an instance of an object

PersonScript.shoot () (at Assets/BAUWERKE/Scipts/javascript/PersonScript.js:31) PersonScript.Update () (at Assets/BAUWERKE/Scipts/javascript/PersonScript.js:24) Ich hoffe es kann mir jemand helfen :)
 class PersonScriptShooting {
 
     var projectile : Rigidbody;
     
     public var damage = 5;
     
     private var go : GameObject;
     
     var Spawnpoint : GameObject;    
 }
 var launchProjectile : PersonScriptShooting = PersonScriptShooting();
 
 // Oben Klassendeklarationen, möglichst viel in ganze Klassen zusammenfassen.
 //
 // Unten der normale Code.
 
 function Start()
 {
 
 }
 
 function Update()
 {
     shoot();
 }
 
 function shoot()
 {
     if(Input.GetButtonDown("Fire1"))
     {
         go = Instantiate(launchProjectile.projectile.gameObject, launchProjectile.Spawnpoint.position, launchProjectile.Spawnpoint.Rotation);
         var RichtungsVektor : Vector3 = Vector3(launchProjectile.Spawnpoint.position.x,launchProjectile.Spawnpoint.position.y,launchProjectile.Spawnpoint.position.z);
         var elevation : Vector3 = Quaternion.Euler(RichtungsVektor) * transform.forward;
         new go.rigidbody.AddForce(elevation * 10);
     }    
 }
Comment
Add comment · Show 3
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 fafase · Feb 09, 2013 at 05:04 PM 0
Share

When you ask a question make sure to use a language that only few may understand. Apart from that, your script looks kinda weird...

avatar image Rixterz · Feb 17, 2013 at 10:07 AM 0
Share

your comment is mixed up between "when you ask a question make sure to use a language that everyone can understand" and "when you ask a question make sure not to use a language that only few may understand" :)

avatar image Skullwing · Jun 06, 2013 at 06:55 PM 0
Share

And fafases comment is totally useless ...

3 Replies

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

Answer by Skullwing · Feb 14, 2013 at 02:15 AM

Problem solved:

 class PersonScriptShooting {
 
     var projectile : GameObject;
     
     var spawnpoint : Transform;
     
     var camera : Transform;
 }
 var launchProjectile : PersonScriptShooting = PersonScriptShooting();
 
 
 function Update()
 {
     shoot();
 }
 
 
 function shoot()
 {
     if(Input.GetButtonDown("Fire1"))
     {
         var spawn : Vector3 = Vector3(launchProjectile.spawnpoint.position.x,launchProjectile.spawnpoint.position.y,launchProjectile.spawnpoint.position.z);
         var clone : GameObject = Instantiate(launchProjectile.projectile,spawn,launchProjectile.camera.rotation);
         clone.rigidbody.AddForce((spawn - Vector3(launchProjectile.camera.position.x,launchProjectile.camera.position.y,launchProjectile.camera.position.z)) * 50, ForceMode.Impulse);
     }    
 }
 
Comment
Add comment · 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
0

Answer by antx · Feb 09, 2013 at 05:03 PM

Hast du Spawnpoint initialisiert? Du hast da ein GameObject namens Spawnpoint deklariert aber das alleine reicht nicht. Da muss dann auch ein GameObject zugewiesen sein. Schau mal ob Spawnpoint im Inspector auftaucht (kenn mich mit JavaScript nicht aus...). Wenn ja, weise dort ein entsprechendes GameObject zu.

in english: Spawnpoint needs to be initialized.

Comment
Add comment · Show 4 · 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 Skullwing · Feb 09, 2013 at 08:33 PM 0
Share

ich hab ein leeres Object namens Spawnpoint an die $$anonymous$$aincamera gehängt und das Script an den First Person Controller.

avatar image Rixterz · Feb 14, 2013 at 05:36 PM 0
Share

he is saying "Have you made a spawnpoint? you've declared a gameobject called spawnpoint but that isn't correct. So you must create a gameobject. Look at the spawnpoint in the inspector(I don't understand javascript)"

because i learn german in school :)

avatar image Skullwing · Feb 14, 2013 at 05:46 PM 0
Share

Some parts are inaccurate, but well translated :)

avatar image Rixterz · Feb 15, 2013 at 06:17 PM 0
Share

thank you muchly! (nice word, "muchly"!)

avatar image
0

Answer by Slev · Feb 09, 2013 at 07:42 PM

I don't speak the language here, but... When you use instantiate it will often instantiate a type that is not a GameObject. For instance, in this case it may be that it's instantiating as a generic Object. Just track through all your codes and see what it could be instantiated as.

You can also use Instantiate(...) as GameObject, to attempt a better typecast.

Comment
Add comment · Show 3 · 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 Skullwing · Feb 09, 2013 at 08:34 PM 0
Share

I tried this but it didn't work.

avatar image Slev · Feb 09, 2013 at 08:40 PM 0
Share

Hmm... you may want to recast the holding variable as a generic Object then, or try instantiating another way.

avatar image Skullwing · Feb 10, 2013 at 01:10 AM 0
Share

I tried a few things, but nothing worked...

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

14 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

Related Questions

Multiple Cars not working 1 Answer

Object Reference Not Set to an Instance of an object 0 Answers

How can I replace an object while keeping the references to that object? 2 Answers

Object Rotation/Character Speed 1 Answer

Object reference not set to an instance of an object 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