If I have a gameobject with many components on it (even scripts that literally have nothing in them), If that gameobject is selected during gameplay, I get lag. Im guessing each component adds stress to the rendering?
How do people work around this? Does it even happen to many of you?
I assume it happens to others because of this same question someone asked (with no answers) http://answers.unity3d.com/questions/890908/unity-lag-on-selection.html
EDIT - Here is some more info.
This is what the scene looks like
Click for image
The 2 scripts are
Click for codes
using UnityEngine;
public class Rotate : MonoBehaviour
{
public float mouseSensitivity = 250f;
void Update()
{
transform.Rotate(0, Input.GetAxisRaw("Mouse X") * (mouseSensitivity * Time.deltaTime), 0);
}
}
using UnityEngine;
public class SomeScript : MonoBehaviour
{
}
Ive also attached the project, feel free to check it yourself.
Just open the scene, press play and have that capsule object selected. Move your mouse around and you should notice stuttering. Unselect the object and the stuttering should stop.
2237844–149253–SelectedGameObjectLag.unitypackage (6.91 KB)
It has no answers because there’s no way anyone can answer it directly- why your program lags is dependent on your program. Have you checked the profiler to see what exactly is causing the lag?
I added more stuff in my original post such as image, code and a simple example project.
What do you mean by “your program”. Do you mean my scripts and what not that I have in unity, or do you mean the unity program itself?
I know that my game can be laggy because of my own scripts, but this problem seems to be more so in regards to unity and out of my control.
Does the example scene not lag/stutter for you when you press play with the capsule selected and start spinning around?
And then the lag stops when its unselected?
I dont see anything noticeable in the profiler.
In mine it’s absolutely no different between playing with the 30 scripts on it versus removing all of the duplicates, so long as nothing else in the scene is touched. It’s not the smoothest rotation in the world (not surprising since it uses raw input), but otherwise no problems.
EDIT: Actually, I see what you’re talking about. It’s reaching out and trying to grab inspector values to fill the window every frame on 30 scripts, so it’s making it look slightly stuttery, but honestly it was really hard to notice on my computer. I think this is exactly the kind of thing you’d expect from having 30 debug logs running every frame, which is essentially what this is. Whether there’s values to fill the inspector window with or not, it’s still reaching for them (on 30 scripts simultaneously).
1 Like