Search Unity

  1. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

Rotation at second prefab iteration

Discussion in 'World Building' started by Ambrose998800, Apr 27, 2019.

  1. Ambrose998800


    Jun 23, 2015
    Hi there!

    I hope this post is in the right subforum. Anyway...

    I try to auto-create a labyrinth. Basicly it works fine, but I have a problem with the room alignement of the second (and any further) iterations.

    All the premade rooms are set up the same way in blender:
    Note that all the ways out of a room are made by an marker (as child of the room) showing into the way out direction. The rooms way in is always the rooms pivot and in positive X direction.

    Now, I instantiate the first generation of rooms as a child of the way out marker and align it via code:
    Code (CSharp):
    1.                     NewRoom.transform.localPosition =;
    2.                     NewRoom.transform.localRotation = Quaternion.identity;
    That works like a charm:

    Then, one further iteration (setup the same way):
    Note that the highlighted room is aligned to global-rotation zero instead of aligned to its parent rotation (the markers rotation).

    Why does it work the first time, but not the second time by the same code, but with just the "i" in the for-loop changed...?
  2. Flavelius


    Jul 8, 2012
    You should post the part of the code that does the layout/produces the problem.
  3. Ambrose998800


    Jun 23, 2015
    There was no problem produced, just the result was wrong.
    It was a blender-Unity export/import twist-thing. I will never get used to that.

    My Maze-Creator is now running like a charm:


    If someone has the same issue with blender-unity .fbx things, here is what I did for clean results:
    - Choose one object orientation for everything you create in blender (even child-objects; for me its X-Forward and Z-Up) and set it in the .fbx exporter.
    - Make sure to clear all objects scale and rotation in blender (ctrl+a in object-mode).
    - Disable Unitys 'Convert Units' at the imported file. Scale the objects down to 1, 1, 1 again.
    - Set all local rotations you need in Unitys scene-editor (they are turned to blenders X-Forward after import).
    - Now all childs (with transform.localRotation = Quaternion.identity) will have the correct orientation when added to another local child-object.

    Thanks a lot Flavelius, you're all time up to help! Cheers