- Home /
Setting name/tag over network.
Hello everyone! I've looked at other solutions online, such as using RPC's and what not, but nothing is helping/similar to my issue.
So i decided to turn towards you, the community!
//My Question//
What would i have to do in order to set a gameObjects name and/or tag over Unity's built in network.
//What I am currently doing//
I am currently sending the chosen team name to the clients through an RPC(RPCMode.ALL) and they are getting it properly client-side, setting their names properly as well, but to other players, their names are just the names of the prefab being spawned in.
I have also tried just sending it regularly and using the players themselves to individually RPC the info to the server and the rest of the players but still nothing.
//Why i need the names/tags set properly//
Just for the kind of team-based game I am creating. Turrets lock onto & fire at anything without the same name as themself, so setting the name/tag of each player is extremely important in my case.
//
Anything i can do to solve my problem? :) Because as of this moment i'm thinking of going as far as to creating individual team based player prefabs -.- haha, and I will cry if it comes to this!
//
Thank you once again for reading,
Sincerely,
Nandor Jozef Bakos
Answer by asdf123 · Aug 25, 2014 at 03:01 AM
i could not understand what are you trying to do, but if you want to change the name of your gameobject so everyone can see just do that:
example:
void Update() {
if(Input.GetKeyDown(KeyCode.G)) {
networkView.RPC("SetName", RPCMode.All, "testname");
}
}
[RPC]
void SetName(string whatName) {
this.gameObject.name = whatName;
}
hope it helps !
Thank you so much for the answer! That is exactly what i am trying to do! Except whenever i try to do that, it doesn't want to work >.<
No errors or anything, it just isn't setting the name of my gameObject anywhere.
See what i'm doing is sending the name through the network manager when a server initializes or a player joins. On the join screen, you have a text field which allows you to set a $$anonymous$$m. You type it in, you click set $$anonymous$$m, then you join a game. That $$anonymous$$m-name will be sent through the server to your player(which is just a camera in this case) and will change the name of said player to whatever you set your $$anonymous$$m to be.
You will then be presented with an options screen where you can choose your ship, and ready up. Once ready, your ship will spawn in and the player is parented to the ship, so the name should also be sent upwards. Only problem is.. i've reached a snag where:
//
Whether i be hosting the server or someone else, the name for the other players who join do not register on everyones side.
//$$anonymous$$y Code//
function OnServerInitialized(){
spawnPlayer();
Debug.Log("Server Initialized");
}
function OnConnectedToServer(){
spawnPlayer();
Debug.Log("Server Joined");
}
function spawnPlayer(){
chosenSpawnPoint = Random.Range(0,spawnPoints.length);
var getSpawnable = spawnPoints[chosenSpawnPoint].GetComponent(playerPresent);
if(!getSpawnable.inTrigger){
spawnedPlayer = Network.Instantiate(Player, spawnPoints[chosenSpawnPoint].position, spawnPoints[chosenSpawnPoint].rotation, 0);
networkView.RPC("setName",RPC$$anonymous$$ode.AllBuffered,$$anonymous$$mTag);
}
else
spawnPlayer();
}
@RPC
function setName(name : String){
playerNames.Add(name);
if(spawnedPlayer != null){
spawnedPlayer.name = name;
var sendName = spawnedPlayer.GetComponent($$anonymous$$mName);
sendName.$$anonymous$$mName = name;
}
}
//And for the name//
nameOfTeam = GUI.TextField(Rect(30,Screen.height/2, 100,20), nameOfTeam);
if(GUI.Button(Rect(30,Screen.height/2-20, 90,20), "Set Team")){
networkView.RPC("setName", RPC$$anonymous$$ode.AllBuffered, nameOfTeam);
}
Not sure what i'm doing wrong here, but if you see anything. PLEASE let me know :P
Its not sending the correct info to the script $$anonymous$$mName attached to spawnedPlayer.
Thank you once again, Sincerely, Nandor
I dont understand some lines in your code, btw you dont need to change name of gameobjects because players wont see them in the game
Essentially the only reason i want to change the gameObjects name is because my turrets look for and lock onto targets that AREN'T on your $$anonymous$$m.
ps. Which lines are you getting stuck on sir? I shall try my best to explain.
Your answer
![](https://koobas.hobune.stream/wayback/20220613161306im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiplayer - Opposite names above players 1 Answer
Raycast detection / lag issue 0 Answers
TextMesh multiplayer/network issue 0 Answers
Player tag not being detected by Unity? 2 Answers