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

After Steamworks.net intergration, getting Steam Overlay to pause game

Discussion in 'Scripting' started by zelrender, Sep 13, 2019.

  1. zelrender

    zelrender

    Joined:
    May 11, 2015
    Posts:
    47
    Unity 2018.3.6f1 Personal
    AC v1.66.7

    Hi there,
    I've followed a guide to get Steamworks.net import and working in unity. That's all fine I think and now have a new script in a gameobject in my project. I want the game to pause when the Steam Overlay is activated and unpause when it isn't. This currently isnt working.

    On a side note I am using Adventure Creator with Unity, but I suspect that this isn't working because of the rest of the code, not that bit.

    Also, I can only test this after the build is uploaded to Steam since the overlay won't open in Unity. Is there a way around this.

    Many thanks, I'm not a coder, here is the code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Steamworks;
    5. using AC;
    6.  
    7. public class SteamScript : MonoBehaviour
    8. {
    9.         protected Callback<GameOverlayActivated_t> m_GameOverlayActivated;
    10.  
    11.     private void OnEnable()
    12.     {
    13.         if (SteamManager.Initialized)
    14.         {
    15.             m_GameOverlayActivated = Callback<GameOverlayActivated_t>.Create(OnGameOverlayActivated);
    16.         }
    17.     }
    18.  
    19.     private void OnGameOverlayActivated(GameOverlayActivated_t pCallback)
    20.     {
    21.         if (pCallback.m_bActive != 0)
    22.         {
    23.             KickStarter.sceneSettings.PauseGame();
    24.             KickStarter.TurnOffAC();
    25.             Debug.Log("Steam Overlay has been activated");
    26.             Time.timeScale = 0;
    27.         }
    28.         else
    29.         {
    30.             KickStarter.sceneSettings.UnpauseGame(1f);
    31.             KickStarter.TurnOnAC();
    32.             Debug.Log("Steam Overlay has been closed");
    33.             Time.timeScale = 1;
    34.         }
    35.     }
    36.  
    37.     // Start is called before the first frame update
    38.     void Start()
    39.     {
    40.         if (SteamManager.Initialized)
    41.         {
    42.             string name = SteamFriends.GetPersonaName();
    43.             Debug.Log(name);
    44.         }
    45.     }
    46.  
    47.     // Update is called once per frame
    48.     void Update()
    49.     {
    50.      
    51.     }
    52. }
     
  2. laessnb

    laessnb

    Joined:
    Jun 10, 2014
    Posts:
    101
    In case anyone else finds this later like I did in 2023: you need to make sure SteamAPI.RunCallbacks(); is being called every update from somewhere. Steamworks.net takes care of this for you in its Update if you have a persistent GameObject.
     
    SeerSucker69 likes this.