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 oreick · Oct 24, 2013 at 05:18 PM · getcomponentrpcnetworkviewnetwork.instantiateviewid

How do I GetComponent from a NetworkView?

The problem I am having is trying to get a component on a prefab that is connected through the NetworkView. Is this possible? What do I need to do exactly?

I have a Player Prefab that has a PlayerLabel on it which controls the displaying of the PlayerName. It also has a NetworkView on it.

I have a SpawnManager that sends each player's (GameObject)Network.Instantiate object to the NetworkManager.

The NetworkManager Is attached to the "GameGo" prefab which also has a NetworkView component.

I am trying to send an RPC in the NetworkManager class that will take the Network.Instantiated object's ViewID, get the GameObject associated with this ViewID, find the "PlayerLabel" component on it, find the "NetworkManager" component on it (which is in gamego), and set the PlayerLabel PlayerName to the one on the NetworkManager.

This is what I have so far. This is my function that will get the spawned player Object with Network.Instantiate.

  void OnServerInitialized ()
     {
         Debug.Log("Server is initialzed.");
         var obj = GameObject.Find("SpawnManagerGO");
         var script = obj.GetComponent<SpawnScript>();
         GameObject player = script.spawnPlayer();
         
         networkView.RPC("Rename", RPCMode.All, player.networkView.viewID, player.name);
     }


This is the RPC function that I try to get the PlayerName with the NetowrkManager on GameGo.

 [RPC]
     void Rename(NetworkViewID ID, string nm)
     {
         //get the network view with the nv id
         NetworkView nv = NetworkView.Find(ID);
         //get the gameobject with the network view
         GameObject go = GameObject.Find(nm);
         var plScript = go.GetComponent<PlayerLabel>();
         var goScript = nv.GetComponent<NetworkManager>();
         Debug.Log (goScript.PlayerName);
         
         
         plScript.PlayerName = goScript.PlayerName;
         go.name = goScript.PlayerName;
         
     }
Comment
Add comment · Show 1
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 Wolfrik_Creations · Dec 11, 2015 at 04:21 PM 0
Share

This is Unity answers for you. Two years and still not answered. Same problem, if I find a fix I'll give you an answer.

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

15 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

Related Questions

Couldn't Invoke RPC Function ! 1 Answer

Changing a variable in another script over the network 1 Answer

Get NetworkPlayer from ViewID 1 Answer

How do you remove RPC's from the RPC buffer that where created on behalf of a player that is now disconnected with an authoritative server? 1 Answer

Looking for some help on manually allocating NetworkViewIDs 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