I heard that Instantiate and Destroy take lots of CPU usage.
What about gameObject.SetActive and GameObject.FindGameObjectWithTag ?
I’d also like to know other functions which needs to be used as less as possible for performance.
I’ve been looking for some answers, but there was no simple answers. Maybe it is hard.
Please give some advice to this beginner^^. Thanks.
I think the easiest way to determine this would be to use the C# Stopwatch class to time how long methods take to run. Something like:
using System.Diagnostics;
timer = new StopWatch();
timer.Start();
for(int i = 0 ; i < 100; i++)
{
//test whatever you want here. For example,
GameObject.Instantiate(somePrefab);
}
timer.End();
Debug.Log(timer.Elapsed);
You generally don’t need to worry about the performance of individual functions. If you have performance problems run the Profiler and see what code is the bottleneck and optimize from there.