- Home /
Problem to moving objects with collider in edit mode
Game objects in project that have Collider and Rigid body can move ver slow in editor mode (scene) I have new PC : i7 3770 , 8 GIG Ram, Geforce GTX 650, Win 8 - 64 bit. same project work smooth with my mac mini 2011 when I moving that objects CPU fan start working too hard. I turn the physic component of game objects off and they moving smoothly.
please help me with that problem. // is there a way to turn off physic calculation in edit mode ?
Answer by Aram-Azhari · Nov 13, 2013 at 12:35 PM
There is no direct solution to this.
However, I have written a little code to turn the colliders off so you can move stuff faster. Once you're done, turn them on again.
Copy the content of this code inside a file called ColliderTool.cs. AND the file should be inside a folder called Editor. If you don't see a folder with that name, just create one.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using System.Linq;
public class ColliderTool : Editor
{
[MenuItem("GameObject/Colliders/Turn off except ignoredcolliders")]
public static void TurnCollidersOffExceptIgnored()
{
try
{
var go = GameObject.FindObjectsOfType<Collider>();
go = go.Where(g => g.tag != "ignoredcolliders").ToArray();
for (int i = 0; i < go.Length; i++)
{
if (!EditorUtility.DisplayCancelableProgressBar("Turning off colliders", "", i / (float)(go.Length)))
go[i].enabled = false;
}
}
catch (System.Exception e)
{
Debug.LogException(e);
EditorUtility.ClearProgressBar();
}
EditorUtility.ClearProgressBar();
}
[MenuItem("GameObject/Colliders/Turn on except ignoredcolliders")]
public static void TurnCollidersOnExceptIgnored()
{
try
{
var go = GameObject.FindObjectsOfType<Collider>();
go = go.Where(g => g.tag != "ignoredcolliders").ToArray();
for (int i = 0; i < go.Length; i++)
{
if (!EditorUtility.DisplayCancelableProgressBar("Turning on colliders", "", i / (float)(go.Length)))
go[i].enabled = true;
}
}
catch (System.Exception e)
{
Debug.LogException(e);
EditorUtility.ClearProgressBar();
}
EditorUtility.ClearProgressBar();
}
[MenuItem("GameObject/Colliders/Turn off")]
public static void TurnCollidersOff ()
{
try {
var go = GameObject.FindObjectsOfType<Collider> ();
for (int i = 0; i < go.Length; i++) {
if (!EditorUtility.DisplayCancelableProgressBar ("Turning off colliders", "", i / (float)(go.Length)))
go [i].enabled = false;
}
} catch (System.Exception e) {
Debug.LogException (e);
EditorUtility.ClearProgressBar ();
}
EditorUtility.ClearProgressBar ();
}
[MenuItem("GameObject/Colliders/Turn on")]
public static void TurnCollidersOn ()
{
try {
var go = GameObject.FindObjectsOfType<Collider> ();
for (int i = 0; i < go.Length; i++) {
if (!EditorUtility.DisplayCancelableProgressBar ("Turning on colliders", "", i / (float)(go.Length)))
go [i].enabled = true;
}
} catch (System.Exception e) {
Debug.LogException (e);
EditorUtility.ClearProgressBar ();
}
EditorUtility.ClearProgressBar ();
}
}
Now you can access the turn off and turn on commands from the menu GameObject/Colliders. If you want some objects to be left alone all the time, just tag them as 'ignoredcolliders'. I hope this helps.
Answer by median · Nov 13, 2013 at 04:31 PM
Thanks Aram Azhari, I really appreciate your help after a few changes at lines 13 and 31 of your script to this: Collider[] go = FindObjectsOfType(typeof(Collider)) as Collider[]; that worked for me.
but I really worry about object that have disabled collider that with this script we turning them to Available. I don't know. It's a big enough project to losing them. is there a way to avoid that?
I'm not sure. What you asked in your first question was to get rid of speed problem. But now you want to disable some objects, but not disable some others.
If some objects are supposed to have their collider disabled all the time and not be turned on, there are two ways to deal with them.
1- One way is to select those objects and remove their colliders (since you're not using them anyway). You can even select them together and remove all colliders from inspector.
2- One other way could be that you create a tag called ignoredcolliders and then select the objects you don't want to be changed and apply this tag. Then use my updated code from the menu but this time the ones that say 'except ignorecolliders'.
btw, The original code works fine without any modification. Are you by any chance using an older version of unity or are you on $$anonymous$$ac? (i'm using 4.2, actually 4.3 from today on pc)
I'm so confused! I think physics must work in play mode not in edit mode! and why the game run smoothly while i cannot move objects in edit mode? the problem gone worst when the scene is become to big. why physics is calculating while we not press play? Your Script worked actually but it really interrupting the level design process.
i set nVidia PhysX in cpanel to CPU or GPU and nothings changed.
( sorry for my bad english )
You're right, although I wonder if moving all those objects in play mode at the same time would be also slow.