Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Quick question about editor shortcuts/macros/scripting.

Discussion in 'Editor & General Support' started by corpsepile, Nov 21, 2023.

  1. corpsepile

    corpsepile

    Joined:
    Aug 14, 2016
    Posts:
    8
    Hi all! Just wanted to check with those more knowledgeable than myself on the best way to handle something. I have some tasks in the editor that I do frequently and was hoping to find the best way to handle them more efficiently.

    Some examples are:
    - toggling the alpha on a set of materials to make them visible/not visible.
    - scrolling through a list of 10 cameras, keeping only one active at a time.
    - moving a gameobject around to a handful of set positions/rotations.

    I assume the best way to handle this is to learn how to create custom editor scripts? I just wanted to make sure there wasn't an obvious "easier" solution, like some sort of macro recorder or utilizing the shortcut manager. (Or if there's an asset that can assist with this!)
    Just for additional clarification, I'm referring to editor specific tasks and not during runtime.
    Thanks!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,338
    Yes, editor scripts are probably the answer here.

    But tackle it from a de-minimus (eg, just what you need) approach first because there are some gotchas.

    For instance, with the first one, if you wiggle a Material's alpha, you are actually changing the asset on disk, generally speaking.

    If you do it in code you must make sure you grab the .sharedMaterial on the Renderer(s) involved, or else you'll start leaking meshes at editor time. I think Unity will tell you but not sure...

    Same with the others in the sense that they change the state of your scene, which will be written the next time you save the scene, so make sure your runtime logic can tolerate whatever state the scene is in.
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,129
    Avoid that! You may end up making a build with an invisible material.

    The better alternative (once you have an editor script) is to get the object's renderer and set its enabled property to false so it won't render, but still run all the scripts and collide and so on.


    And be sure to check the asset store. Pretty sure what you want to do is already available as some kind of asset, possibly even free. ;)
     
  4. corpsepile

    corpsepile

    Joined:
    Aug 14, 2016
    Posts:
    8
    Thanks for the feedback everyone! I was hoping there would be a "simple" macro recorder of some sort but it sounds like editor scripts are my best bet!