[Newbie] Need help with FPS drop !

Hello guys, I’m using this code to spam my arrows skill, it’s about 10 arrows at the same time and it make FPS drop down a lot. Do you have any solution for this? thank you!

    IEnumerator delaySkill(){
        m_anim.Play("Skill1");
        yield return onesecond;
        for (int i = 0; i < m_Skill1SpawnPoints.Length; i++) {
                GameObject newArrow = Instantiate (arrow) as GameObject;
            newArrow = Instantiate (arrow, m_Skill1SpawnPoints [i].transform.position, Quaternion.identity);
            newArrow.transform.position = m_Skill1SpawnPoints [i].transform.position;
                Rigidbody rb = newArrow.GetComponent<Rigidbody> ();
            rb.velocity = m_Skill1SpawnPoints [i].transform.forward * arrowspeed;
        }
        m_anim.SetBool("IsIdle",true);
        attack = true;
        SkillReady = true;
        yield return new WaitForSeconds(SkillDelay);
        SkillReady_1 = true;
    }

If the FPS drops during the entire time they’re in the air, that’s the physics calculations; you can (and should) optimize that by picking and choosing which layers it’s possible for the arrow to hit (in particular, they should definitely exclude each other).

If the FPS drops for just the one frame, you should google “object pooling” - basically, don’t instantiate them when they’re fired, but instead instantiate them ahead of time and just activate them when they’re fired.

1 Like