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

Changing Editor camera controls?

Discussion in 'Scripting' started by Pia, May 13, 2009.

  1. Pia

    Pia

    Joined:
    Feb 16, 2009
    Posts:
    78
    Our artists are veterans in 3D Max and they asked me to write a script which changes the camera controls in the Unity editor so they behave like the camera in 3D Max. Would this be possible? I couldn't find any way to access the editor camera while scanning through the API docs.
     
  2. najaa3d

    najaa3d

    Joined:
    Jan 22, 2022
    Posts:
    29
    Fast forward 13 years, now end of 2022 -- is this possible yet? I find the existing built-in Unity Camera controls to be deficient/annoying. I'd much rather manipulate my scene using my own Camera controls. !!!

    This is so central to the development experience; I hope Unity will enable customization soon, if they haven't already.
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,194
    There's some access to how the camera controls work - you can turn off the god-awful acceleration and smoothing they introduced a while back.

    If you want to go harder, it's possible to get direct access to the Scene View's camera and move it around. Overriding the mouse controls would be a lot harder - that would be something like hooking up to OnSceneGUI, and handling mouse inputs from the current Event and Use()ing all the drag events if there's nothing being dragged... or something. It sounds hard and annoying and broken. Feel free to try, though.

    It might also be that the current shortcut system allows you to disable the "shortcuts" for camera movement, but I doubt it?

    It'd be very nice if there was official support for modifying the camera movement in the scene, but I suspect that stuff is gnarly with 10 year old roots, and not very easy to extract. There was some person making a camera plugin a while back, which I know because they spent a lot of time complaining on the forums how hard and broken it was.
     
  4. TomasKucinskas

    TomasKucinskas

    Unity Technologies

    Joined:
    Dec 20, 2017
    Posts:
    60
    Yes! To add to Baste's answer we do have a shortcut manager where you can change individual shortcuts, make profiles similar to other digital content creation software, and import/export those profiles (a new feature in 2022.2 I think).

    In addition, I've been involved in another thread where users wanted to override scene view controls and as a result, we landed a feature in 2023.1 that made it possible for everyone to do their own scene view controller with custom boost functionality (well it can be used for much more than that).

    If you do try to do your own scene view controller, I would be very interested to see how it goes and get to know what are the pain points now if any.
     
    Baste likes this.
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,194
    I still don't understand how to use the Shortcut Manager properly, so since you're in this thread maybe you can help?

    I want a shortcut that's as accessible as a [MenuItem] - ie it works no matter what has focus. But a [Shortcut] won't fire if the Game View has focus during play mode. Is there any workaround, or do I still have to ignore the Shortcut Manager for global shortcuts and stuff global shortcuts into [MenuItem]s in hard-to-find menus with hardcoded shortcuts?

    As a concrete example, this is what I have:
    Code (csharp):
    1. [MenuItem("Window/RainInternal/Clear Console %#k")]
    I'd love to do:
    Code (csharp):
    1. [Shortcut("Rain/Clear Console", KeyCode.K, ShortcutModifiers.Action | ShortcutModifiers.Shift)]
    But that won't fire if I enter play mode unless I click outside the game view, which makes me sad.
     
  6. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,524
    I'd just like to mention that 5 years ago it was already possible to essentially "replace" the default camera controls. I did this over here, mainly to introduce a speed slider (which we now have out of the box, so it's kinda obsolete). Note that I would not necessarily recommend using this approach as it's kinda hacky. The key here is / was that
    OnSceneGUI was executed before the default camera behaviour. So just calling Use on the event prevented the default action. I also implemented an auto speed increase the longer you hold down a movement key. With the speed slider you could get really slow and exact movements.

    In addition if you're looking for saving camera presets, I made a little tool over here ^^. It saves the camera position, orientation and the mode (orthographic or perspective). Of course in the recent Unity versions we have much more settings like FOV, camera speed, occlusion culling and some other settings that could be stored as well. Luckily those new settings actually have been exposed to scripting via SceneView.CameraSettings. Since that class is Serializable it would be trivial to add those settings to my presets :)
     
    TomasKucinskas likes this.
  7. TomasKucinskas

    TomasKucinskas

    Unity Technologies

    Joined:
    Dec 20, 2017
    Posts:
    60
    @Baste It looks like you have bumped into a limitation of Shortcut Manager. Since it is intended as a tool for executing Editor actions and we don't want those actions possibly interfering with your game controls, we ignore non-menu item shortcuts in game view while playing. We do have a button for disabling menu shortcuts in game view(a new feature in 2022.2 or 2023.1) but we don't have the ability to allow all shortcuts while playing at the moment.

    If I wanted to have a customizable shortcut that works in play mode while the game view is focused I would register a regular shortcut with Shortcut Manager and then track for its key combination inside EditorApplication.update. Then once that key combination is hit, execute the action and make sure it doesn't happen multiple times until the next key down event. It's not the cleanest solution but I think it could work. Am I making sense here?

    Also, could you tell me more about what exactly are you trying to do with game view shortcuts?
     
  8. TomasKucinskas

    TomasKucinskas

    Unity Technologies

    Joined:
    Dec 20, 2017
    Posts:
    60
    @Bunny83 Nice camera controller! I was surprised it is still working perfectly in new Unity versions.
     
  9. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,194
    Honestly a lot of them!

    I might want to open a game-specific window that has information I care about. I do want "clear console" to be available, so I can clear the console (and notice if there's new errors) without having to grab the mouse and make the console window visible.

    Mostly it's just that I want to be able to control when the shortcuts are active! It's probably bad if editor shortcuts are enabled by default with the game view active, but an option would be an improvement for sure.


    Related - is the "context" argument to the type of the window that has to be focused? The documentation for ShortcutManager just says "Optional shortcut context type" which doesn't really tell me anything useful.
     
  10. TomasKucinskas

    TomasKucinskas

    Unity Technologies

    Joined:
    Dec 20, 2017
    Posts:
    60
    Okay, I see. I doubt we will be able to do an option to enable all shortcuts because if we look at the shortcut manager window, we have a number of global shortcuts that will most likely clash with common game controls. So you'd probably have to remap those keys on a "Play mode editor work" profile.

    On the other hand, we could make a new shortcut type that will allow for execution while in play mode and game view. Would this kind of shortcut solve all your use cases? I'd bring it up with my managers for discussion.

    Yes, you are correct. The context argument is a type for a window that should be focused on when the shortcut is executed. Typical usage looks like this:

    Code (CSharp):
    1.     [Shortcut("My/Shortcut", typeof(SceneView))]
    2.     public void MyShortcut()
    3.     {
    4.         Debug.Log("My Shortcut Works!");
    5.     }
     
    Baste likes this.
  11. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,194
    That would fix it! That being said, now that I look at the API for ShortcutManager, it wouldn't be that hard for us to make a thing that runs in the game (editor only) and calls the same method as the global shortcut, by looking at the key codes.

    So it's not hard, it's more that from reading the docs and looking at the shortcut manager, it was never obvious to me that
    a) the shortcuts were not meant to work in play mode
    and
    b) it is possible to do a workaround by reading off keys from a public API

    I don't actually know if "I want an editor shortcut in play mode" is a weird corner case only I'm interested in, but as far as I can tell neither the API docs or the manual ever spell out an answer to the question "when are custom shortcuts available", so if that info was there I would probably have been less confused.
     
    TomasKucinskas likes this.
  12. TomasKucinskas

    TomasKucinskas

    Unity Technologies

    Joined:
    Dec 20, 2017
    Posts:
    60
    Yes, the manual page for Shortcut Manager is a good outline for old features but some information is missing. I've sent your feedback through the in-site reporting tool.

    Okay, then I'll try to get this "Game View Shortcut" feature into our plans for the next release.

    Also, let me know how this workaround of listening for shortcuts works for you.