Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Freeze transforms on scaled Game Object?

Discussion in 'Editor & General Support' started by ridethefader, Nov 20, 2020.

  1. ridethefader

    ridethefader

    Joined:
    Jun 17, 2019
    Posts:
    44
    Long story short, I need to rescale my entire game by half and reimport my assets from Blender at the correct scale.

    Ideally, I'd be able to parent everything to a Game Object in Unity, scale the Game Object by .5, then freeze the transformations of the Game Object so when I reimport my assets at .5 scale from Blender, it matches up with the project in Unity. Otherwise, if I can't freeze transforms in Unity, and I rescale in Blender, the objects will reimport at .25 scale.

    What would be the solution?
     
  2. ridethefader

    ridethefader

    Joined:
    Jun 17, 2019
    Posts:
    44
    Anyone have a solution? I just need an easiest way to do this. Heres my workflow so far, but it still requires me to manually rescale every single object in my scene back up one by one:

    1. Assign all mesh to a single Game Object in Unity
    2. Scale Game Object down by 50%. Now everything looks as it should be. But now I have to rescale my source assets in Blender...
    3. Rescale source assets from Blender and reimport to Unity, but now they are HALF the size of what they should be in my scene. So now I have to scale them all up. I could select them all and manually just enter "1" into the scale field, except a lot of the assets arent scaled exactly to 1, some are a little more or less than 1.

    Theres a lot of assets. I need a better solution here. Anyone?
     
  3. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,315
    Seems to me like you only need to scale the positions of the objects, but keep their scale the same.

    Here's a quick snippet that will do just that on all the objects in the scene -- tailor it to your purposes if you need to exclude certain objects or limit it to a selection. If you need to modify other attributes, such as collider size etc. you can do that here too.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. public static class ScalePositionsUtility {
    5.     // this will scale all loaded transform positions by half,
    6.     // relative to the world origin.
    7.     [MenuItem( "Tools/Scale Positions" )]
    8.     static void ScalePositions () {
    9.         var transforms = GameObject.FindObjectsOfType<Transform>();
    10.  
    11.         foreach( var t in transforms ) {
    12.             Undo.RecordObject( t, "scale position" );
    13.  
    14.             t.position *= 0.5f;
    15.  
    16.             // modify any other attributes you need to
    17.  
    18.             var coll = t.gameObject.GetComponent<BoxCollider>();
    19.  
    20.             if( coll != null ) {
    21.                 Undo.RecordObject( coll, "scale collider" );
    22.  
    23.                 coll.size *= 0.5f;
    24.                 coll.offset *= 0.5f;
    25.             }
    26.         }
    27.     }
    28. }