edit values for multiple objects concurrently

Lads,
I’m creating a scene with a lot of box colliders. I’d like to be able to tweak certain properties like ‘Mass’ for all colliders at the same time. Currently I have to open each box collider and tweak the values one at a time, and this is time consuming… any suggestions?..

Thx,

Stef

The most straightforward way, in the editor, is to just use prefabs for the boxes! If you create and instantiate a single prefab, as long as you don’t change the ‘mass’ value on the instantiated box you can change the value on the prefab in the project view (or by clicking apply in the scene view), and all the instances in the scene will automatically update to reflect that change.

If, for some reason, this won’t work for you (for example, if you have to do this at runtime), you can do it using Unity’s tagging system!

Whenever you create one of these boxes, give it a tag corresponding to a ‘type’ of box (this allows you to have several independently-controlled boxkinds). Then, when you want to change the mass of all the boxes, use this function-

public void ChangeMassWithTag(string tag, float newMass)
{
    foreach(GameObject obj in GameObject.FindGameObjectsWithTag(tag))
    {
        Rigidbody objBody = obj.rigidbody;
        // Make sure the rigidbody actually exists!
        if(objBody != null)
        {
            objBody.mass = newMass;
        }
    }
}

This will work both at runtime, and in the inspector- just call it like this:

// to change the masses of 'barrel' objects to 5.6
ChangeMassWithTag("barrel", 5.6f);