Forum rules - please read before posting.

Pause game when Steam Overlay is active

Is this a function AC has built in somewhere?

Comments

  • To pause the game - yes. Integrated with Steam - no.

    AC can be paused/resumed in two ways via script. One is to simply pause the game manually:

    AC.KickStarter.mainCamera.PauseGame (); // Pause
    AC.KickStarter.stateHandler.RestoreLastNonPausedState (); // Resume
    

    The other, which may be more appropriate, is to turn on your "Pause" menu (if you have one) so that the user can resume the game themselves:

    AC.PlayerMenus.GetMenuWithName ("Pause").TurnOn ();
    

    As for calling this when Steam Overlay is active, you'll need to make use of a script/system that provides a hook for such an event. This one looks promising.

  • edited September 2019

    Great, I'll look into that. Just came to mind, and it might be a bit ham-fisted, but couldn't I just make an input of Shift + Tab to bring up the Pause menu?

  • So I'm putting in your code for this function but it's not pausing the game. Anything I'm missing?

    This is the full script:

    using System.Collections;
    using Steamworks;
    using System.Collections.Generic;
    using UnityEngine;

    public class SteamScript : MonoBehaviour
    {
    protected Callback m_GameOverlayActivated;

    private void OnEnable()
    {
        if (SteamManager.Initialized)
        {
            m_GameOverlayActivated = Callback<GameOverlayActivated_t>.Create(OnGameOverlayActivated);
        }
    }
    
    private void OnGameOverlayActivated(GameOverlayActivated_t pCallback)
    {
        if (pCallback.m_bActive != 0)
        {
            AC.KickStarter.mainCamera.PauseGame(); // Pause
            Debug.Log("Steam Overlay has been activated");
        }
        else
        {
            AC.KickStarter.stateHandler.RestoreLastNonPausedState(); // Resume
            Debug.Log("Steam Overlay has been closed");
        }
    }
    
    // Start is called before the first frame update
    void Start()
    {
        if (SteamManager.Initialized)
        {
            string name = SteamFriends.GetPersonaName();
            Debug.Log(name);
        }
    }
    
    // Update is called once per frame
    void Update()
    {
    
    }
    

    }

  • Are the Debug logs showing in the Console? I can't tell if this is due to your Steam integration, or AC, otherwise.

  • edited September 2019

    Also just added using AC; since it didn't have it, but that did not help either.

    btw - this will be needed for anybody releasing an AC game on steam since its a requirement for certification (as I understand it) that bringing up the Steam Overlay must pause the game.

  • At what point are you testing the overlay? During gameplay?

    Try this code instead - it's safer than the above, since it should also work if the game is paused - and also turn off AC completely:

    // Pause
    KickStarter.sceneSettings.PauseGame ();
    KickStarter.TurnOffAC ();
    
    // Resume
    KickStarter.sceneSettings.UnpauseGame (1f);
    KickStarter.TurnOnAC ();
    

    Failing that, try the method of turning on the Pause menu - fare any better?

  • I will try the new code.

    I tried the pause menu code, but that didn't work. I am trying ingame, unfortunately you cannot test the overlay from the unity, have to upload a build to Steam, so its always a faff to test.

    I almost suspect that its this part that isn't working - hooking into the Overlay activation if (pCallback.m_bActive != 0)

    Do you have some simple code (maybe non AC based to be safe) which prints a message onscreen I could throw in there to test?

  • Sorry, I can't debug non-AC code. Debug.Log statements should still show up in your Player log file, however.

  • If I'm running my game from Steam, are these player log files still created and visible? Since this can only be tested from Steam.

  • Tried the new bit of code. Didn't work (or wasnt triggered I guess).

    There must be so many ppl on this forum who have had to do this before for their own releases. It's a real shame the culture on here is that everyone just waits for you to answer instead of helping out when they can as well.

  • Well this is a dead end for me then.

    I'm trying a different way where if I push shift and tab then the game will pause, for now I'm just trying to get a console or screen readout.

    ``using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class LShiftandTabPausing : MonoBehaviour
    {

    bool LShiftandTab = false;
    
    // Start is called before the first frame update
    void Start()
    {
    
        void LShiftTabPause()
    
        {
            if (LShiftandTab == false && Input.GetKey("left shift") && Input.GetKey("tab"))
            {
                LShiftandTab = true;
                print("Pressed keys down");
            }
            else if (LShiftandTab == true && (Input.GetKey("left shift") == false || Input.GetKey("tab") == false))
            {
                LShiftandTab = false;
                print("Released one of the keys");
            }
        }
    
    
    
    
        // Update is called once per frame
        void Update()
        {
    
        }
    }
    

    }``

    I have this script in a gameObject, but when using Object:SendMessage, which I trigger from an Active Input, and calling the LShiftTabPause function, I get this error:

    SendMessage LShiftTabPause has no receiver!

    At a loss here.

  • If I'm running my game from Steam, are these player log files still created and visible?

    I believe so.

    SendMessage LShiftTabPause has no receiver!

    You may need to make the LShiftTabPause function public. An alternative would be to use Object: Call event, used to call this function (also public) when attached to a prefab asset file.

    I wouldn't recommend calling a function that reads Input from an Active Input, though. Better to just run the code in the Update loop - but we're getting away from anything AC-related here.

  • For the information of others:

    It appears that the original issue I was having is a problem with the current Steamworks.net wrapper and which I had firstt should have worked. Someone here is having the same issue: https://github.com/rlabrecque/Steamworks.NET/issues/303?fbclid=IwAR2JfY_3SPAEitC4zICK-kqU8FVcXaoYvCdjPCMQo4nYUta7aCYbsyBZ1SA

    Hopefully this gets resolved by steamworks.net soon.

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.