- Home /
80 tags for one game?
Hello unity3D.I have a question about tags.Is 100 tags for a game too much?For example my game have 8 characters and each character uses that 10 tags each.If this is too much tags or should i try a different method for find objects?If anyone knows?Can you please tell me?Also what is the maximum tags a game should have?
public var player : Transform;
var enemy : Transform;
var camLerpAmount : float =0;
var cam : Transform;
var explosion: GameObject;
public var roarCamera : Transform;
public var mouth : Transform;
var GenzuPlanetRoar : GameObject;
var Teleport : GameObject;
var spawn : Transform;
function Awake (){
player = gameObject.GetComponent(Transform);
}
function Start() {
player = GameObject.FindWithTag("Player").transform;
enemy = GameObject.FindWithTag("Dummy").transform;
cam = GameObject.FindWithTag("TaiichiCamera").transform;
roarCamera = GameObject.FindWithTag("RoarCamera").transform;
mouth = GameObject.FindWithTag("Jaw").transform;
renderer.enabled = true;
collider.enabled = true;
}
function OnCollisionEnter(collision : Collision){
if(collision.gameObject.tag == "Dummy"){
collision.transform.gameObject.animation.Play("Hit_Flying");
collision.transform.gameObject.animation["Hit_Flying"].speed =0.00050;
collision.rigidbody.AddForce (Vector3.forward * 2000000);
player.transform.gameObject.animation.Play("Burn_To_Hell_Part_2");
player.transform.gameObject.animation["Burn_To_Hell_Part_2"].speed = .25;
camLerpAmount = Mathf.Clamp01 (camLerpAmount + 0f);
renderer.enabled = false;
collider.enabled = false;
}
yield WaitForSeconds(2.5);{
cam.transform.position = roarCamera.transform.position - roarCamera.transform.forward;
camLerpAmount = Mathf.Clamp01 (camLerpAmount + 5f);
Instantiate(GenzuPlanetRoar,mouth.transform.position,mouth.transform.rotation);
cam.transform.Rotate(0,360,0);
}
yield WaitForSeconds(2.5);{
cam.transform.position = roarCamera.transform.position - roarCamera.transform.forward;
camLerpAmount = Mathf.Clamp01 (camLerpAmount + 5f);
Instantiate(Teleport,spawn.transform.position,spawn.transform.rotation);
}
}
Not sure if it is a problem but what are you doing with all those tags? Usually you can use GameObject.GetComponent, GameObject.GetComponentInChildren, ... and so on to find most of the things you need.
well yea that too...=o.The reason for the tags is that when i start the round 1 for the first battle,player is suppose to view player 2 automatically unless theres another way of doing this
The reason is because i dont know how to add a transform to the object before the round starts without using findwithtag
Answer by LaneFox · Jun 03, 2015 at 12:58 AM
There is nothing wrong with having that many tags.
However you should consider the side effects of doing so, there is likely a better approach to your design than using 10 unique tags for each character but its impossible to give any advice on that without any code to reference.
Eventually the process of creating and maintaining them is going to be unwieldy or counterproductive. Afte rall, you're only using 100 but already asking if it is safe. In terms of performance, tags are actually pretty fast to find objects in the scene and such so it just depends on your situation.
i put a reference up.Also would it be better if i use devluz method?
Yes that would be better. You could also probably reference a lot of that through the Inspector by making some of that stuff public variables ins$$anonymous$$d of finding it at runtime. If another Character needed it then you could just find it through that reference ins$$anonymous$$d of scanning the scene with a tag filter.
I have tried adding the getcomponent but it still needs a tag.Is there another way of me being able to put the transforms in the inspector from the start?
For example Jaw is on the Prefab, correct? So why search for it at runtime? This is a useless operation, just make a public variable so it is exposed in the inspector, then drag the Jaw into the field. Now it's always known and you can reference it directly in the script.
Do this wherever possible to reduce runtime operations.
Im trying to understand what your saying,with the gameObject in the inspector it works but with the transform it doesnt go in.For example.when i put the character and the object with the script in scene mode and put the transform in the inspector it works. but when i save the prefab to project folder it doesnt work.Is there a way i cang et the transform that i put in the scene into the project folder prefab?
Answer by Duugu · Jun 03, 2015 at 06:50 PM
Using a lot of comparisons with tags imho is actually pretty slow, as string comparisons are slow at all. :)
Answer by ArmanOhanian · Jun 03, 2015 at 10:40 PM
I don't quite know if too many tags are bad, but I I hope this will help you tidy-up your code a bit.
Instead of coding this:
if(collision.gameObject.tag == "Dummy"){
collision.transform.gameObject.animation.Play("Hit_Flying");
collision.transform.gameObject.animation["Hit_Flying"].speed =0.00050;
collision.rigidbody.AddForce (Vector3.forward * 2000000);
player.transform.gameObject.animation.Play("Burn_To_Hell_Part_2");
player.transform.gameObject.animation["Burn_To_Hell_Part_2"].speed = .25;
camLerpAmount = Mathf.Clamp01 (camLerpAmount + 0f);
renderer.enabled = false;
collider.enabled = false;
}
I'd organize it like this:
if(collision.gameObject.tag == "Dummy"){
collission.die();
// Then code a public die() method for whatever it is you are tagging as dummy.
}
...then I'd code a public die() method for whatever it is I am tagging as dummy.
Are you saying that if the object i am using to collide with the dummy gets destroyed within contact?Because im trying to get the object to find the transforms as soon as the round starts
I am not sure what exactly you're trying to achieve. What I am observing, and I may be wrong here, is that all the code seem to belong better in your class tagged 'dummy'.
Again, I've only seen a fraction of your code and don't know your intent.
No thats the whole thing.What i am trying to achieve is that i want the object to get the transform without using the FindWithTag $$anonymous$$ethod.
Your answer
Follow this Question
Related Questions
Multiple Colliders With Mechanim 1 Answer
Is there a solution to when colliders bypass? 2 Answers
handling collision with two objects of the same tag 1 Answer
Holding objects, How to deal with object clipping 2 Answers
Make AI run from Player 1 Answer