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 slehmann101 · Jan 28, 2014 at 08:55 PM · variablevaluepassingsetting

When passing a value it becomes null

I have a script called update, this script is given to another script via:

 public Update up;

This script is not null as I am successfully able to do:

 up.run(1.0f);

I then need to pass up to a script of my player object which i have created through:

 cam.SetTarget((Instantiate(player,Vector3.zero,Quaternion.identity) as GameObject));

the script is then put into a variable via:

 Player_Movement p =  player.GetComponent<Player_Movement>();

and then I try to give the Player_Movement script the Update script via:

 p.setUpdate(up);

which simply runs a function in Player_Movement like so: private Update backgroundUpdate; public void setUpdate(Update script){ backgroundUpdate=script; Debug.Log ("set"); } this function is being run successfully, as seen in the log. The problem is that I am then trying to use the run function of the Update script from the player and then I get a null reference exception. The Update was set before I tried to run this.

I don't have much experience with unity but to me it seems like a really obtuse way to do it, as all I am trying to do is set a script in a prefab to a script possessed by a gameObject, however I could not find any way to do it except through such a convoluted manner. However even if this is the wrong way to do this (I am sure it is) I would like to know why I am getting a null reference exception. I apologize if this isn't clear, please do not hesitate to ask any clarifying questions.

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

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

19 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

Related Questions

Trying to pass a float value from a prefab to another script that compares values from multiple prefabs 1 Answer

How to get a value from an array within another script. 1 Answer

Help on a Power-Up Sequence 1 Answer

Editing a variable from another script on collision 3 Answers

How to set a variable equal to another variable in another gameobject? 2 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