Forum rules - please read before posting.

Vsync question

Hey guys,

Is there any way to give the player the option to enable/disable Vsync through AC while a build is running? Or is this only though the "Display Dialog Options" when playing a build from the beginning?

Thanks,
Jason

Comments

  • Enabling and disabling vsync setting is not supported directly by AC (as far as I know, I could be wrong again, haha), but is quite easy to implement in a settings menu with minimal extra code.

    QualitySettings.vSyncCount is probably what you're looking for.
  • Thanks, Snebjorn. I'm actually going in another direction now. I'm trying to incorporate a Quality Settings menu for the player to adjust in-game and am hoping to use this asset: https://www.assetstore.unity3d.com/en/#!/content/33781

    It has the option to toggle Vsync.

    To activate this menu in game, all the player needs to do is press "escape". However, I want to make a menu button to simulate pressing the escape button. So the player will click a button in a menu and that simulates pressing escape, toggling this menu. I'm a bit lost at this point on how to do this. I've look at the Simulate Input option through the Menu editor, but this seems to control items in the InputManager. I feel like I'm overlooking something obvious here...
  • edited April 2017
    Input cannot be simulated easily... AC and other plugins simply fake it, just by running the requested method, bypassing input completely (ie: you don't need to simulate a left click if all you have to do in your code is run the method that runs your actionlist,etc). Anyway, try connecting just the canvas and one of the panels(as rect transform) on that UI into the AC menu manager, you should be able to open and close the menu that way (I remember doing something similar with a rewired menu once before). Still, you'll have to check how to prevent that UI from firing when the escape button is pressed. I'd recommend asking the author of that plugin on how to prevent that. You may have to comment some code or who knows, he may just have an option on the plugin already for that, but you'll have to ask.
  • @jasong: I've actually used that exact asset in my own AC projects. I ended up ripping the code apart for better integration with the AC menu system, but it was quite simple to set up.

    Sharing the code here is not allowed, but if you need general advice on how I did it, I'd be happy to help with that.
  • @Alverik Great suggestion about just using the UI Canvas to turn it on and off. I'm running into a bit of a snag with this method however. With this plugin the canvas prefab is a child of another prefab without a canvas component. Adding necessary canvas components to the parent prefab will toggle on/off the menu graphics, but functionality within the menu doesn't work.

    Pressing escape toggles the menu with proper functionality. I notice that the checkbox for the prefab in the inspector is driven by the escape key, whereas simply linking the canvas components doesn't toggle the checkbox on/off when hooked up to an AC menu. I'm stumped on where to go from here and welcome any suggestions you might have.

    @Snebjorn Thanks for the offer to help, if I can't get the above method to work I just might take you up on it!
  • As far as I can tell it would be easiest to know which c#/Js method is run by the plugin when the escape button is pressed. Then just make a custom action that finds that object and then calls that method. That way you can use it on an AC button or anywhere really. You'd only really need to make sure the object holding the menu is in every scene to avoid nullreferences.
  • @Alverik it looks like the custom action might be the best way to go, however please bear with me as scripting is not one of my strengths.

    In the C# script there is a function "OpenQualitySettingMenu();" which toggles the menu, this is what is run whenever the escape key is pressed.  If I were to make a custom action for this, how would I call this function?

    Maybe @Snebjorn could chime in as well?? :)
  • edited April 2017
    First declare a variable with the same type as the script name in your custom action.
    private ScriptToFind _script;

    Then inside the Run() function in your custom action add:

    _script = FindObjectOfType<ScriptToFind>();
    _script.OpenQualitySettingMenu();

    This will find the first object with said script and call it's OpenQualitySettingsMenu() method. Replace ScriptToFind for the actual name of the script that has the OpenQualitySettingsMenu() method (but don't type the .cs part, just the actual name). Remember AC has a custom action template script, just duplicate that then rename the file and the name inside the script (you'll find there are two places where you have to replace the name). You should probably take a look at the custom actions text tutorial to get your bearings (but you won't need any of the advance options, just basically paste the code, variable in area marked as "declare variables here", and the rest inside the Run function).

    You could then stop the menu from opening by pressing the escape button, by commenting the lines of text checking for the input (like Input.GetButton().)
  • Thanks @Alverik! That got it working!
  • One thing to keep in mind is that stuff that doesn't affect AC directly (eg. graphics quality settings) can be handled through the standard Unity GUI functionality without involving AC. The vsync toggle as an example could be handled through a script hooked directly into OnValueChanged() on the relevant Toggle element in the Menu - and this is in fact the route I've taken with this.

    If the Menu as a whole is made visible to the AC menu system, you can then use that to let AC handle opening and closing the menu.

    Hope that made sense - still on my first cup of coffee this morning ... :-)
  • Thanks @Snebjorn! Yeah, that makes sense. I'm toggling this menu on using a Run Action List option through an AC menu. This AL toggles the Quality Settings menu on while turning of the currently displayed menu, and the other way around when going back. Seems to be working good so far!

    Thanks again for all your help guys!
  • Perhaps this is moot by now, but by linking AC Variables to Options Data and writing a custom Action, you can create your own Options settings and embed them within AC's Profile data (so that you can have a per-user VSync option etc).  It's covered in this tutorial.
  • Hey guys,

    I ran into an issue with this menu after upgrading to AC1.57a from 1.56. The problem is either the custom action or there's a bug with the "Pause game when enable" menu option.

    The Quality Menu asset mentioned above is turned on by calling a function within the asset's C# script by using a Custom Action in AC. Using the Custom Action by itself in an Actionlist the Quality Menu opens and then immediately closes which isn't desired (I want it to stay open), but I found a workaround by adding an AC menu to also toggle on at the same time with "Pause game when enable" option checked. The "Pause game when enable" option of the AC menu makes the Quality Menu remain open.

    However, when upgrading to AC 1.57a the "Pause game when enable" option no longer keeps the Quality Menu open. I'm not sure if there's now a bug with the "Pause game when enable" option or if it comes down to my Custom Action missing something important and I can no longer rely on the "Pause game when enable" option to keep this menu open.

    I have test scenes showing this behavior in 1.56 and 1.57a and can send if needed. I'm on Unity 5.5.0, but I've also tested on Unity 5.6 so I don't think it's a Unity thing. Any help is much appreciated!

    Thanks!
  • If the quality menu was always immediately closing, then that sounds like the issue to address.  Coupled with your custom action, it could be any number of things at play here.  However, as things changed with v1.57a I don't see any choice but to see it for myself.  Please PM it in as small a filesize as you can and provide steps to recreate.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.