Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 mohitsabhi · May 30, 2017 at 02:37 AM · prefabsslidernull reference exceptiongameobject.find

Player UI prefab slider Null reference

I have a Multiplayer game Player UI which is instantiated on start. However a Slider named and Tagged as Throttle under the Prefab throws a Null reference when being called under start function when using;

Throttle = GameObject.Find ("Throttle").GetComponent ();

Thanks.

Will share the code on a kind response.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jawchewa · May 30, 2017 at 04:33 AM

When using get component, you have to specify the type of the component that you are trying to get. I think what you want should look more like this:

 Slider Throttle = GameObject.Find("Throttle").GetComponent<Slider>();

This will get you the slider component, assuming that the object named "Throttle" exists at the point when you call this, and has a slider component attached.

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 mohitsabhi · May 30, 2017 at 05:23 AM

@Jawchewa Thanks very much for your kind response. Tried but think I am still doing something wrong, coz still giving a Null Reference.

Sharing in scripts and the screen for the scene;

a. first is the Player Controller Script which has the Throttle Slider script and the lower part has Player Setup script which is used to Instantiate the PlayerUI Prefab under which the Throttle slider resides.

b. Screen shot of the Prefabs folder showing the hierarchy of the Player Prefab and the right-side is the PLAYER Inspector.alt text

Thanks for your time and await yours.

Brgds

link text


screenshot.png (451.6 kB)
player-control-and-setup.txt (2.6 kB)
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 Jawchewa · May 30, 2017 at 01:36 PM 0
Share

Hmm. $$anonymous$$y guess is that the start function in your ship movement script is probably getting called before the start function of your player setup script, and so at the time when you want to get the throttle, it probably doesn't exist in the scene yet. Try changing your player setup script by replacing the Start method with Unity's built in Awake method to force it to be called before your ship movement's Start method.

avatar image mohitsabhi Jawchewa · May 30, 2017 at 05:19 PM 0
Share

Thanks so much. Tried it like this;

void Start () { if (!isLocalPlayer) { DisableComponents (); AssignRemoteLayer (); } else { sceneCamera = Camera.main; if (sceneCamera != null) { sceneCamera.gameObject.SetActive (false); }

 }
 GetComponent<Player> ().Setup ();

} void Awake ()

 // CREATE PLAYER UI AND CONTROLS
 {
 playerUIInstance = Instantiate (playerUIPrefab);
 playerUIInstance.name = playerUIPrefab.name;
 }

This sorted for the Local player, however when the Client joins in now see Two PlayerUIs created on the Heirarchy window and on the Network Player canvas, screen shot attached.

How do I ensure the same Player UI used ins$$anonymous$$d of duplication.

Thanks once again.

Brgds

avatar image mohitsabhi mohitsabhi · May 30, 2017 at 05:25 PM 0
Share

Am unable to attach the Screen shot but its showing TWO PlayerUIs on the Heirarchy window and on the Client canvas.

avatar image
0

Answer by alirazabrame · Oct 08, 2021 at 08:05 PM

Hi! I have the same problem. I want to load loading screens on button click. I always got null pointer exception.

I make changes to resolve my problem:

Step-1: Add my all canvases in an empty object

Step-2: Assign all canvases same tag

Step-3: Inactive all canvases

Step-4: Active the required canvas on button click

Step-5: Atlast activate the script function

May be your problem different. But I suggest you to Instantiate prefab before calling the script function.

alt text


loading-ui-slider.jpg (381.5 kB)
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

106 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 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 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

Prefab UI Slider misses the fill and background items... 0 Answers

Unity3d Script does not work anymore 1 Answer

How to make or find advanced UI assets 1 Answer

How to assign slider to float: Spin, on a gameobject 1 Answer

Unity UI slider seems to increment in random whole number values. Need advice please 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