GameObjects perfomance

Hello,
I have about 20 different playable characters(2D) and each one have different techniques / animations / icones of techniques. The simpliest way is to create for each character GameObject and put to these objects scripts, then disable unused objects at Start().

Let’s suppose theres 20 characters, all of these characters have about 4-5 techniques and 4-5 icones.
So at the beginning it’s generate about 90~ sprites. But how about perfomance? Currently theres not much objects, but in future I’ll add more characters and my destination device is mobile, so older devies can not have enough power to handle it without lags.

Another way is to create that one choosed character at runtime but it’s a lot of work to do.

Well, you could have the game technically start already (Load the scene), but have there be a loading screen viewed to the player.

In an IEnumerator you can instantiate the objects with small delays between them.
Say something like:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SpawnCharacters_Handler : MonoBehaviour {

    public float SpawnDelay = 0.2f;
    public GameObject LoadingScreen_GUI;
    public List<GameObject> Characters;

    void Start()
    {
        LoadingScreen_GUI.SetActive(true); // You can keep it active by default in the end, but this way you can keep it disables whilst working.
        StartCoroutine(SpawnCharacters()); // Activate the Spawning of your Characters
    }

    private IEnumerator SpawnCharacters()
    {
        // Run through all of your Characters
        foreach (GameObject character in Characters)
        {
            // Spawn a character and wait for "SpawnDelay" in seconds, Rinse and Repeat
            Instantiate(character, transform.position, Quaternion.identity);
            yield return new WaitForSeconds(SpawnDelay);
        }
        LoadingScreen_GUI.SetActive(false); // Get it out of the way, feel free to use Epic Fades and what not.
    }
}

Don’t worry too much about the details like where you spawn the characters, you’ll know that better than I do :wink:

It’s just an example, but it comes down to having to spawn the characters at runtime and give the player the illusion they’re still waiting patiently.

You’ll have to sacrifice: “Less of a framedrop / spike” => “Longer loading times”.
The size of the sacrifice depends on how intense the cycle becomes.
Aka, more characters, more loading time if you want to keep the spike just as low. :slight_smile:

I hope that helps, there may be other ways, but this is a good trick :3