- Click anywhere in the CPU Usage graph
- We can see that our Update method is taking up a much larger portion of the frame
- Change the bottom section of the profiler from timeline to hierarchy view
- The timeline view is a good visualization, but the hierarchy view provides more actionable information
- Order the hierarchy view by “Time ms” and expand “PlayerLoop” all the way down to the script logic
- By ordering the view by “Time ms” we can narrow down what is taking the CPU so long to execute
- FindObjectsOfType is taking up some time, so let’s fix that
- Switch to Visual Studio
- Convert interactables to a private member variable
- Initialize interactables in the Start method
- It’s best to initialize this at the start of the scene instead of every frame
- This works because we know our scene won’t change
We decreased how long it takes for our script to run each frame but we aren’t done