S
S
Sergey Ivanov2019-06-22 17:51:56
Unity
Sergey Ivanov, 2019-06-22 17:51:56

Unity why is OnTriggerStay causing a lot of lag?

i have a code

private void OnTriggerStay(Collider other)
    {
        if (enemy == null)
        {
            if (other.gameObject.tag == "Crip")
            {
                if (other.gameObject.GetComponent<Crip>().isMyTeam != gameObject.GetComponent<Crip>().isMyTeam)
                {
                    enemy = other.transform;
                    prior = Priority.Enemy;
                }
            }
            else
                return;
        }
        else
            return;
    }

it weighs in at 100 bots why does it cause lag even though the same code in OnTriggerEnter does not cause lag

Answer the question

In order to leave comments, you need to log in

4 answer(s)
F
freeExec, 2019-06-22
@keksmr

Because it GetComponentis a heavy function, and every update you have it is called twice on each bot. You can save the gameObject InstanceId and if it has not changed, then there is nothing to run all this logic over again.

C
Conan the Barbarian, 2017-08-18
@borgore

If your avatar is set through the img tag, then like this:

img {
  object-fit: cover;
  object-position: center;
}

If via background:
.image {
  background: url() no-repeat center;
  background-size: cover;
}

In general, if you want to get the answer you need, then send a link to the sandbox. It will be better this way.

I
Ivan Ukhov, 2017-08-18
@Igooooood

set the parent to position: relative;
and ave
position: absolute;
top50%;
transition: translateY(-50%);

I
Igor Koch, 2017-08-18
@amux

https://jsfiddle.net/whata/r2ng5f6h/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question