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 TreeFish · Mar 26, 2015 at 08:58 PM · uinetworkinginstantiatetext

Populate UI Text with appropriate Network View

How would I initiate/change a local UI Text (or any) Element with a value from a Network-Instantiated prefab?

My basic setup is as follows, without any effect: Scene:

  • Camera

  • UiElement

Connection is established using MasterServer (Unity) - participants and visual effects are cloned from prefabs like so:

 Network.Instantiate(playerPrefab, new Vector3(... etc.

state synchronization works properly as well.

The UI element has the following script attached to identify the value source:

 public GameObject Player; //this is the player prefab
 public Text energyDisplay; //this is the Text field inside the 

 void FixedUpdate () {
     if(Player.GetComponent<NetworkView>().isMine){
         energyDisplay.text = Player.GetComponent<PlayerStats>().energy.ToString();
     }
 }

Debug of "energyDisplay.text" as well as " Player.GetComponent().energy.ToString();" shows the correct value - however the text field does not change...

I also tried to instantiate a copy of the UI for each individual participant - check ownership and populate, but the result was just the same as above.

What am I doing wrong?

Comment
Add comment · Show 6
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 LegendWill · Mar 26, 2015 at 09:21 PM 0
Share

Have you tried just using Update ins$$anonymous$$d of just Fixed Update? If is YOUR "energy" then only YOU should see it right? Why not just attach this script to the player and just use GetComponent. It will take a bit less to do. Sorry, lol. I got off track. Just answer the first question xD

avatar image TreeFish · Mar 26, 2015 at 09:28 PM 0
Share

Thanks Legend,

I ended up assigning Text directly to the player - so I would mark your answer as correct if you post it as one. However, I'm still curious on how to get values from Gameobjects with NetworkView and add them to any local UI(or other element..)?

avatar image LegendWill · Mar 26, 2015 at 09:38 PM 0
Share

I'll post it as an answer then so others can see if it they have the same issue.

What are you trying to do? You want to get a value from a UI text and store it in a string or somewhere else?

avatar image TreeFish · Mar 26, 2015 at 09:41 PM 0
Share

basically as described above: NetworkInstantiated Gameobject -> read Value -> change Text on local UI

it works up until the local UI part...

avatar image TreeFish · Mar 26, 2015 at 09:46 PM 0
Share

as stated above I did and I made 100% sure that the targets were set properly. Although both energyDisplay as well as .energy.ToString()... were equal. I can even see the change in the editors text (Script) box - only thing not updating was the UI element on the view...

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by LegendWill · Mar 26, 2015 at 10:33 PM

Since it is YOUR "energy" then only YOU should see it right? Why not just attach this script to the player and just use GetComponent. It will take a bit less to do.

Comment
Add comment · Show 2 · 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 TreeFish · Mar 26, 2015 at 10:53 PM 0
Share

Hi Legend,

sorry for the confusion, I think I just now understood what you meant. However, this wasn't the solution that ended up working -

the only way I found to populate a local UI was to replace it with a Network.Instantiated one (is now initialized as a child of player) - and it works.

For some odd reason the reference to the local UI Element must be different once Network instantiated variables float around... is there a crack in the system? :)

avatar image LegendWill · Mar 26, 2015 at 11:43 PM 0
Share

That's a bit weird... Perhaps something with Unity 5?

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

2 People are following this question.

avatar image avatar image

Related Questions

Server not spawning players model on connected players 2 Answers

show sync var on two text ui (unet - networking) 3 Answers

Multiple gui instantiation issues 0 Answers

Changing the UI text value from server to Client side 0 Answers

UI Text showing weird string value? 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