Optimization FPS in my game?

Hello.
I have a couple of problems in my application.
I have a not standard List with 36 elements in it.

public class ShopScript : MonoBehaviour{
 
public void BuyRocket(int num)
    {
        for (var i = 0; i < Itemses.Count; i++)
        {
            Itemses[i].ActiveRocket.SetActive(false);

            if (num == i)
            {
                Itemses[i].ActiveRocket.SetActive(true);
                Debug.Log(Itemses[i].Price);
            }
            Debug.Log("items " + Itemses[i]);
        }

    }

}
[System.Serializable]
public class Items
{
    public GameObject Prefabs;
    public int Price;
    public bool IsBought;
    public GameObject ActiveRocket;

}

This script I attached on some Button. When I click on them - my fps drops on <20

public class BuyItemScript : MonoBehaviour
{

    public ShopScript ShopScript;
    public int RocketIndex;
   

    void Start()
    {
        var itemScript = GameObject.Find("ShopScript");
        ShopScript = itemScript.GetComponent<ShopScript>();
    }

    public void BuyRocket()
    {
        ShopScript.BuyRocket(RocketIndex);
    }
}

Debug.Log is a very slow operation.

2 Likes

This. Remember debug.log is not just putting a string on the console, it’s also doing a full stack trace. This gets expensive, especially in loops.

2 Likes

Thanks for the help, after removing debug.log everything was working perfectly.