- Home /
How to disable certain error messages?
I am currently working on a powerup system where my player changes tag. I also have an enemy shooting at the player who has the tag ''player''. Problem is when i use the powerup the tag changes to ''player2'' the enemies doesn't hit me anymore(that isn't a problem) but i also get 999+ errors saying that there isn't a object with tag ''Player'' wich is true. The problem here is that all those error messages makes the game drop fps so is there a way to disable those error messages?
You could just program it properly to not throw errors...
Im a beginner with c# and if i knew how i wouldn't post about it
If you want help you should show some code, you seem to know the source of your error though, as your text conveys.
so, is the power-up supposed to make you invisible to enemies? There's probably a better way that you can tell them that, instead of just changing the player's tag. Maybe you could set a canBeTargeted
bool to false and make the enemy check that, and don't fire if so.
Answer by mangosauce_ · Mar 19, 2021 at 03:42 PM
I think the way to go forward here is to avoid using a tag change as a way to change enemy behavior. Disabling the error messages is only skirting around the problem (and I'm 92% sure it can't be done in this case), though it is true that the messages are probably what's caused the performance drop.
Try something like this: add a static variable to the player script, as show below.
public class PlayerScript : MonoBehaviour
{
public static bool isPoweredUp = false;
}
Then, if you need to check whether the player has picked up the powerup, you can use this if statement:
public class EnemyScript : MonoBehaviour
{
private void Update()
{
if (PlayerScript.isPoweredUp == true)
{
//Enemy behavior code
}
}
}
Just be sure to set PlayerScript.isPoweredUp to true when the powerup is picked up, and false when its effects wear off. CompareTag is only really effective if the tag remains the same on a given gameObject. Try to use the above method instead of changing the tag. :)
Thank you so much for your help! I would never came up with this solution
Your answer
