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 godofwarfare115 · Apr 20, 2014 at 11:23 AM · gameobjectgetcomponentnullrefresh

UnityEngine.GameObject.GetComponent[WeaponBehavior]

So i am trying to make a multiplayer survival game like DayZ.... I have multiplayer down so far.. But when i go to pick up a weapon it wont let me. It just gives me this error UnityEngine.GameObject.GetComponent[WeaponBehavior] Please someone help me. The full error is this

NullReferenceException UnityEngine.GameObject.GetComponent[WeaponBehavior] () (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/UnityEngineGameObject.cs:28)

any help would be GREATLY appreciated thank you

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 Clonkex · Apr 20, 2014 at 12:50 PM 0
Share

Quick suggestion: Edit the post, select the error and click the "Code" button. It will stop [WeaponBehavior] turning into a link.

avatar image Benproductions1 · Apr 20, 2014 at 01:24 PM 0
Share

Whatever it is you're trying to get a WeaponBehaviour component from doesn't have one attached, so GetComponent returns null, meaning nothing. When you try to do something with nothing, you get a NullReferenceException. You'll need to post code to get a more definitive answer and solution to your problem.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Clonkex · Apr 20, 2014 at 01:56 PM

A NullReferenceException when calling GetComponent means the component you're trying to find doesn't exist. Make sure the component you're trying to access is actually attached to the GameObject from which the script calling GetComponent is running.

If the component is inside a different GameObject, you have a couple of options. You can use GameObject.Find() to find the GameObject which has WeaponBehavior in it, or you can create an inspector-exposed variable to let you drag the GameObject onto the script from inside the editor. In case you don't know how to create a variable that's visible and editable from within the editor, here's how:

JavaScript:

 var WeaponControlObject : GameObject;

C#:

 public GameObject WeaponControlObject;

For more information, read the manual on using GameObjects and components from scripts.

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

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

22 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

Related Questions

Why is this null? Finding a script on an object 3 Answers

Unity GetComponent return value 2 Answers

Assign collider and linerenderer to list 1 Answer

Weird GetComponent error 2 Answers

What is the order of execution for the instantiated object's GetComponent.Script.DoSomething? 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