Apply transformation

Hello! I Have some house prefabs at my scene but the rotation of the prefabs x axis is -90 degrees. I want to make it 0 but I don’t want the objects to be rotated. How can I apply the transformations of the prefabs?

Extra parenting to sort out troublesome assets:

Check your pivot/center and global/local buttons in the Scene window in the editor.

Shortcut keys are Z and X to toggle those.

You could un-parent all the child items, set the parent to rotation 0,0,0 and then re-parent the children. However, this will break the prefab connection and is cumbersome.

Depending on how much time you want to spend, extending the Editor functionality is useful.
Personally I found I needed to do tasks like these this numerous times, so I created an Editor script to accomplish this:

using UnityEngine;
using UnityEditor;
public static class DebugMenu
{
    [MenuItem ("Debug/Transform/MakeLocalRotation0 (Child Adjust)")] 
    public static void MakeLocalRotation0 ()
    {     
        if (Selection.activeGameObject != null) { 

            var selectedTransform = Selection.activeGameObject.transform;

            //Create a list of all the GOs children
            List<Transform> childrenList = new List<Transform> ();
            for (int i = 0; i < selectedTransform.childCount; i++) {
                childrenList.Add (selectedTransform.GetChild (i));
            }

            var numChildren = childrenList.Count;

            for (int i = numChildren - 1; i >= 0; i--) {
                var child = childrenList [i];
                child.transform.parent = null;
            }          
            selectedTransform.localEulerAngles = Vector3.zero;

            //Restore children
            for (int i = 0; i < numChildren; i++) {
                var child = childrenList [i];
                child.transform.parent = selectedTransform;
            }

            DebugMenu.MarkSceneDirty ();

        } else {
            Debug.LogError("No object selected");
        }
    }
}

Put this in a .cs file in an Editor folder.
Unity will create a “Debug” menu in the upper menu bar. You then select the gameObject, then choose
Debug->MakeLocalRotation0 .

1 Like

This code saved me a lot of time! thank you! However I add the code to editor but it didn’t work. After some time chatting with chat.gpt I got this code

using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement; // Added this line for EditorSceneManager
using System.Collections.Generic;

public static class DebugMenu
{
    [MenuItem("Debug/Transform/MakeLocalRotation0 (Child Adjust)")]
    public static void MakeLocalRotation0()
    {
        if (Selection.activeGameObject != null)
        {
            var selectedTransform = Selection.activeGameObject.transform;

            //Create a list of all the GOs children
            List<Transform> childrenList = new List<Transform>();
            for (int i = 0; i < selectedTransform.childCount; i++)
            {
                childrenList.Add(selectedTransform.GetChild(i));
            }

            var numChildren = childrenList.Count;

            for (int i = numChildren - 1; i >= 0; i--)
            {
                var child = childrenList[i];
                child.transform.parent = null;
            }
            selectedTransform.localEulerAngles = Vector3.zero;

            //Restore children
            for (int i = 0; i < numChildren; i++)
            {
                var child = childrenList[i];
                child.transform.parent = selectedTransform;
            }

            MarkSceneDirty();

        }
        else
        {
            Debug.LogError("No object selected");
        }
    }

    private static void MarkSceneDirty()
    {
        if (!Application.isPlaying)
        {
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }
    }
}

I’m not sure what it changed and how it works :smile: I don’t know C# but it did