• 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
Question by lucas216erickson · Nov 23, 2016 at 03:41 AM · networkingmultiplayerphotonmultiplayer-networkingrpc

Photon RPC Only Working Halfway

Hello everyone, thank you for taking the time to give me a hand here. I am using PUN for my server, and I am trying to have colored names and UI sprites that show where your teammates are in the world. When I instantiate a player, I want the color of their names and the actual text of the names to change. (I am using 3d text for the names.) I also want to change the color of the triangle that marks each player. Each player gameobject already has a canvas and a white triangle attached to it. It also has the 3d text as a child of the main object. Here are the two main functions for spawning the player:

 public void SpawnPlayer(Vector3 SpawnPos)
     {
         MyPlayer = PhotonNetwork.Instantiate ("Character", SpawnPos, Quaternion.identity, 0);
         Debug.Log ("Instantiated player at " + SpawnPos);
         AnimComponent = MyPlayer.GetComponentInChildren<Animator> ();
         Debug.Log (AnimComponent.name);
         MyPlayer.transform.Find("CharacterModel").GetComponent<Animations> ().enabled = true;
         MyPlayer.GetComponent<NetworkCharacterScript> ().Anim = AnimComponent;
         TeamScript = MyPlayer.GetComponent<Team> ();
         PlayerUIScript = MyPlayer.GetComponent<PlayerID> ();
         PlayerUIScript.TeamScript = TeamScript;
         MyPlayer.GetComponent<RespawnUI> ().enabled = true;
         MyPlayer.GetComponent<Respawn> ().enabled = true;
         MyPlayer.GetComponent<Respawn> ().TeamScript = TeamScript;
         MyPlayer.GetComponent <PlayerShooting>().enabled = true;
         MyPlayer.GetComponent <MouseLook> ().enabled = true;
         MyPlayer.GetComponent<MovementScript>().enabled = true;
         PlayerUIScript.TeamScript = MyPlayer.GetComponent<Team> ();
         PlayTri = MyPlayer.transform.FindChild ("PlayerTriangleCanvas/PlayerTriangle").gameObject;
         PlayTri.tag = "Triangle";
         NameText = MyPlayer.transform.FindChild ("CharacterName").gameObject;
         NameText.tag = "NameText";
         GetComponent<PhotonView> ().RPC ("ChangeTrisAndName", PhotonTargets.All, SavedVarsScript.CurrentPlayerName);
     
         PhotonNetwork.isMessageQueueRunning = true;
     }

This is the method that actually synchronizes the colors and text:

 [PunRPC]
     public void ChangeTrisAndName(string PlayerName)
     {
         ProcessLog ("Function executed for " + PlayerName);
         TeamScript.TeamID = MyTeamID;
         GameObject[] Triangles = GameObject.FindGameObjectsWithTag ("Triangle");
         foreach (GameObject Tri in Triangles) 
         {
             if (Tri.transform.parent.transform.parent.GetComponent<Team> ().TeamID == 1) 
             {
                 Tri.GetComponent<Image> ().color = Color.blue;
                 Tri.tag = "TrianglesBlue";
             }
             if (Tri.transform.parent.transform.parent.GetComponent<Team> ().TeamID == 2) 
             {
                 Tri.GetComponent<Image> ().color = Color.red;
                 Tri.tag = "TrianglesRed";
             }
         }
         GameObject[] Names = GameObject.FindGameObjectsWithTag ("NameText");
         foreach (GameObject Name in Names) 
         {
             if (Name.transform.parent.GetComponent<Team> ().TeamID == 1) 
             {
                 Name.GetComponent<TextMesh> ().color = Color.blue;
                 Name.GetComponent<TextMesh> ().text = SavedVarsScript.CurrentPlayerName;
             }
             if (Name.transform.parent.GetComponent<Team> ().TeamID == 2) 
             {
                 Name.GetComponent<TextMesh> ().color = Color.red;
                 Name.GetComponent<TextMesh> ().text = SavedVarsScript.CurrentPlayerName;
             }
         }
     }

Sorry for the long scripts, but most of this stuff is actually relevant to the problem. What happens is when I join a game, both players' screens will display the same message that says "Executed function for " and will both display the same player name- the name of the last person to join and the person who actually executed the method. The colors and text for your player is changed, but the person on the other screen's name is still white and displayed as "PlayerName." I can't tell if this is a problem with local variables, the RPC, or something else. I appreciate your help. :)

Edit: The "ProcessLog" method just displays some text on the screen. It is my own debug method that is visible in the final build.

Comment

People who like this

0 Show 0
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

1 Reply

  • Sort: 
avatar image

Answer by lucas216erickson · Nov 23, 2016 at 04:57 AM

Bump... I'm really stumped on this one. I've changed this thing around so many times, this must be the 7th or 8th try...

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

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

How do i use RPC's to set a object active in the hierarchy for all Players in the room and also how do i synchronize UI events focused on a VideoPlayer (Play, Pause etc.)) 0 Answers

Whats the best beginners tutorial for Photon Networking with Unity 2 Answers

Photon RPC 2 Answers

Instantiate with Photon 0 Answers

[PHOTON] Transform not synching correctly 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