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

PlayMode Options - Scene View Spawning and Full Screen Game Views!

Discussion in 'Assets and Asset Store' started by Jacob-Williams, Sep 24, 2016.

  1. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267

    What is it?
    PlayMode Options is a small toolbar that sits at the bottom of your scene view and provides a number of helpful options.

    Here is a quick break down of the features:
    • Spawn your player object at the location of the scene view camera. (Unreal, anyone?)
    • Launch your game view in true full-screen on your primary monitor or any secondary monitors.
    • Setup a hotkey to enter and exit play mode.
    • Upon exiting the game, game views launched in a new window will be disposed of, freeing up your desktop real estate.
    • Choose from any of the game view's resolution settings on the fly.
    • Selectively lock an individual position axis, making it a solution for not only 3D games, but 2D as well.

    The plugin will be cheap, unobtrusive, and drastically speed up your testing time.

    Update
    Version 1.1 has been submitted to the asset store with a few new features:
    • When spawned at the scene view location, you can also have the player follow the scene view's rotation as well.
    • There is now a menu option to mute the game's audio when entering play mode.
    • Holding CTRL + pressing your play mode hotkey will use Unity's default game view for the next play session only (a useful feature for testing something quickly without creating a new game view window)
     
    Last edited: Oct 14, 2016
    theANMATOR2b likes this.
  2. 2dgame

    2dgame

    Joined:
    Nov 24, 2014
    Posts:
    83
    I'm interested. Unfortunately don't have the time to help testint at the moment.
     
  3. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    Thanks for your interest, and no worries - I should be submitting to the Asset Store later today. I added a video to the original post to show off some of the features.
     
  4. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    The plugin has now been submitted to the asset store and is awaiting approval.
     
  5. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    I'm happy to announce that PlayMode Options is now available on the Asset Store!
     
    Last edited: Oct 15, 2016
    2dgame likes this.
  6. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    Version 1.1 has been submitted to the asset store with a few new features:
    • When spawned at the scene view location, you can also have the player follow the scene view's rotation as well.
    • There is now a menu option to mute the game's audio when entering play mode.
    • Holding CTRL + pressing your play mode hotkey will use Unity's default game view for the next play session only (a useful feature for testing something quickly without creating a new game view window)
     
    2dgame likes this.
  7. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    Version 1.1 is now available on the Asset Store for only $5!
     
  8. Inspeinre

    Inspeinre

    Joined:
    Jun 15, 2013
    Posts:
    44
    Hi!
    OSX Yosemite

    [Exception] DllNotFoundException: user32.dll
    Rethrow as TypeInitializationException: An exception was thrown by the type initializer for PlayModeOptions.PlayModeSceneEditor
    0. PlayModeOptions.DisplayMonitors.QueryDisplays() D:/Projects/PlayModeOptionsDLL/PlayModeOptionsDLL/DisplayMonitors.cs:66
    1. PlayModeOptions.PlayModeSceneEditor..cctor() D:/Projects/PlayModeOptionsDLL/PlayModeOptionsDLL/Editor/PlayModeSceneEditor.cs:35
    2. RuntimeHelpers.RunClassConstructor() /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.CompilerServices/RuntimeHelpers.cs:101
    3. UnityEditor.EditorAssemblies.ProcessEditorInitializeOnLoad() /Users/builduser/buildslave/unity/build/Editor/Mono/EditorAssemblies.cs:123
     
    Last edited: Oct 14, 2016
  9. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    As it turns out, the native API I was using to get monitor information was Windows only. I think I have a temporary solution until I can find something that works better, but I don't have a Mac to test it. If you don't mind, send me an email to jacob@cheapdevotion.com and I will send you a new version to test.
     
  10. 2dgame

    2dgame

    Joined:
    Nov 24, 2014
    Posts:
    83
    I really like the idea of this asset, however at the moment I'm still having several issues.

    1. Playmode changes itself to fullscreen window. Reproduce like this:
    • Turn on fullscreen playmode. Start game or don't, doesn't matter.
    • Switch to default playmode. Start game by pressing play button or F5, either works.
    • Exit playmode by pressing F5.
    • Playmode changes itself back to fullscreen mode.
    • If switching to default playmode again and start then exit via F5 again, this won't happen. It seems this bug only occures when you turned on fullscreen mode manually before

    2. Rotate to scene view doesn't do anything for me. The 'keep x/y/z rotation' options are all unticked, however my Player tagged object won't start with any rotation. Note that the position change to the scene view does work.

    3. Starting in fullscreen mode doesn't keep cursor lock mode. In my game the cursor gets locked on start. If I start the game in fullscreen mode the cursor gets visible and unlocked.
    Finally two requests, though I don't know if these are possible in Unity.

    1. It would be nice if we could start play mode by pressing F5 even when the scene view isn't in focus. Right now, if you do anything in the inspector for example, the F5 shortcut won't work and you need to click in the scene view first which kind of makes the shortcut redundant since you could then click on the play button instead of the scene view as well.

    2. If I have the game view tabbed with other windows I am working in, it would be cool if when exiting play mode then window I was working in before would come back to the front. I know this does already happen, if the game view is tabbed behind the scene view (scene view comes back to front on exiting), however often times I like to have my scene view side by side with the game view while playing, thus I have the game view tabbed next to it along with a Script inspector tab for example.​
     
    Last edited: Oct 14, 2016
    theANMATOR2b likes this.
  11. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    @2dgame - I have been able to reproduce this bug and will get it fixed immediately. In the meantime, if you leave it on Full Screen Window, and hold CTRL when pressing F5, it will launch in Default Play Mode so you can use both modes as the need arises.

    Are you running into any other issues?
     
  12. 2dgame

    2dgame

    Joined:
    Nov 24, 2014
    Posts:
    83
    I updated my post above with some more issues I am having.

    Here comes one more suggestion. When holding SHIFT or ALT (for example) and pressing th start hot key, the player object would remain at it's default location even though 'spawn at scene view is turned on'. Bonus if this works in combination with your CTRL+F5 to stay in default mode feature.

    Thanks for looking into all this stuff :)
     
  13. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267


    For the first one, I'm going to venture a guess that you're using the StandardAssets FPS Player. In FirstPersonController.cs, the rotation is set on every update, so it's getting set correctly, but the code it setting it back. If this is the case, I can write a version of this script that allows programatically setting the rotation and send it along.

    As for the second, this is a bug and should be fixed. I assume we are losing the cursor lock because of creating (or moving) the game view. I will look into this right away.

    I'm not sure the second one here is possible, but the first one shouldn't be a problem. I will look into it and let you know.
     
    theANMATOR2b likes this.
  14. 2dgame

    2dgame

    Joined:
    Nov 24, 2014
    Posts:
    83

    Your guess put me on the right track. I am not using the StandardAssets FPS Player. I do however have a script that interferes with the players rotation and in fact even own set rotation in the inspector gets ignored. I'll have to get this fixed myself.
    In order to do this, can you tell me at what point your asset changes the players rotation, so I can take that rotation into account? On Awake? On Start? Thanks
     
    Last edited: Oct 14, 2016
  15. 2dgame

    2dgame

    Joined:
    Nov 24, 2014
    Posts:
    83
    So my rotation script reads the players starting rotation on Start() now and respects my inspector values. If I turn on 'spawn at scene view' the scene view rotation is still being ignored. If your asset would set the players rotation on Awake() my script should recognize that rotation, shouldn't it? Is it possible your asset sets the rotation on Start()? If so, could you set it earlier, on Awake() for example?
     
  16. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    Thanks to @Inspeinre, I been made away of a bit of a breaking bug if you're using Unity on a Mac. I've quickly patched the bug with a temporary solution and have uploaded it to the Asset Store, but if you need the fix sooner shoot me an email with your invoice number and I will get it to you.
     
  17. Inspeinre

    Inspeinre

    Joined:
    Jun 15, 2013
    Posts:
    44
    I am willing to wait, hope you solve the problem:rolleyes:
     
  18. 2dgame

    2dgame

    Joined:
    Nov 24, 2014
    Posts:
    83
    So, I just wrote a script to test at what point PlayMode Options changes the player objects position and rotation to the scene views and found out that they only get changed at the 3rd frame into the game. I think this is far from ideal since it won't let you use or even know the players position and rotation in the first 3 frames and need to write extra code for all scripts that use those variables to wait for 3 frames.
    I'm curious about the reason why the adjustment doesn't happen earlier, ideally before runtime, like on EditorApplication.playmode changing to isPlaying for example?
     
  19. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    The reason for this was pretty simple - in the end, I didn't want to tamper with the player's position before play mode has started in the event that there is a problem when setting it back. When starting this project, my goal was to not touch a player's scene in a way that wouldn't be reverted when exiting play mode.

    I'm curious to know what your use case is here - I have no doubt we can find a solution that works better. Why is it that you need to know the player's position and rotation in the first frame on game start?
     
  20. 2dgame

    2dgame

    Joined:
    Nov 24, 2014
    Posts:
    83
    I understand and that is a good reason not to change to position/rotation in edit mode.

    My player rotation works like this. I have a camera childed to the player who's rotation is initialized to the players rotation on Start. From there on the camera changes its roation in the Update function according to mouse input. Its rotation also gets smoothed out a bit so it can't be directly linked to the players rotation. The player object then syncs its rotation to that of the camera in FixedUpdate for proper physics. This has worked really well for me.
    If I now suddenly change the players rotation mid-game (or 3 frames in) the camera won't know that and the rotation will get overwritten in the next FixedUpdate.
    My suggested solution would be that the players rotation is already set when the game starts.
    If you'd set the players position/rotation on Awake for example, everything should work fine and values would get reverted on exiting play mode as well.

    Sure, in my explained case I could write an ugly workaround.. Just wait with any rotation logic until after the 3rd frame.
    But apart from this use case there could be a ton more reasons why the values shouldn't be changed 3 frames in but before. Maybe the scene view camera is outside a trigger volume, which fires off a cut scene when the player is inside and I want to start outside of the volume (normal position would be inside the volume). If the players position only gets changed after 3 frames the trigger would still fire off which I wouldn't want.
     
  21. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    @2dgame - There is no way to ensure that code runs in the first frame inside an Editor script, but I think I have a workaround. To make the "exit playmode" hotkey work, I create a game object in the scene on play. I can move the set position/rotation into the awake method in this script, and it should run before any Start methods in the scene. Will test this today and let you know how it works out.
     
    2dgame likes this.
  22. 2dgame

    2dgame

    Joined:
    Nov 24, 2014
    Posts:
    83
    Looking forward to it!

    Ran into 2 more issues. Please don't mistake my posts as negative feedback. I just really like the asset and want to help you improve it.

    1. When there is no object with the set tag (player) in the scene and you start the game, the game pauses with an error:

      IndexOutOfRangeException: Array index is out of range.
      PlayModeOptions.PlayModeSceneEditor.OnPlayModeChange () (at D:/Projects/PlayModeOptionsDLL/PlayModeOptionsDLL/Editor/PlayModeSceneEditor.cs:233)


      This is a problem when you are developing a RTS game for example and want to use playmode options for the fullscreen and shortcut features but not the position/rotation stuff.
      I suggest only looking for the tagged object when 'spawn at scene view' is ticked. If then it doesn't exist provide a warning message, that doesn't prevent the game from running.

    2. From the dropdown menu, pick 'default play mode'. Start the game.
      If you press 'space' now (which I do for jumping) the game pauses and a dropdown menu to pick a display appears in the game view.
      This behaviour stops once you focus another dropdown menu from the playmode options in the scene view.
     
  23. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    The first one has already been fixed and will be in the next version. Thanks for bringing the second one to my attention - I will get it fixed ASAP.
     
    2dgame likes this.
  24. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    Version 1.2 has just been submitted to the store and contains numerous bug fixes. If you need this new version sooner than the next week or so, email your invoice number to cheapdevotion (at) gmail (dot) com and I will send you the build.

    @2dgame - the only issue I couldn't immediately fix is the three frame delay in setting the position and rotation. There is no way to reliable do this without setting the position and rotation BEFORE entering play mode, and doing this will require some major refactoring on my part. It's still on the list, but it's going to take a little time.
     
    2dgame likes this.
  25. 2dgame

    2dgame

    Joined:
    Nov 24, 2014
    Posts:
    83
    Okay, so I just tried out version 1.2
    Unfortunately, apart from the rotation thing, most of the issues I mentioned are still present. Maybe you just forgot them when you fixed other bugs? Here they are:

    • Starting in fullscreen mode doesn't keep cursor lock mode. In my game the cursor gets locked on start. If I start the game in fullscreen mode the cursor gets visible and unlocked.
    • The F5 shortcut only works when the scene view is in focus. If you do anything in the inspector for example, the F5 shortcut won't work and you need to click in the scene view first which kind of makes the shortcut redundant since you could then click on the play button instead of the scene view as well.
    • Not a big deal but a small glitch: From the dropdown menu, pick 'default play mode'. Start the game. If you press 'space' now (which I do for jumping) the game pauses and a dropdown menu to pick a display appears in the game view. This behaviour stops once you focus another dropdown menu from the playmode options in the scene view.
    I hope you can get around to these. They are also more important to me than the rotation fix.