Jump to content

KSP API - game event Quit


Recommended Posts

Hello

sorry for stupid question... i am a newbie, so shame on me :)

I need to know if there is any Game Event, that can me detect leaving the game (closing). Maybe such us leaving the main menu. I read the documentation https://anatid.github.io/XML-Documentation-for-the-KSP-API/class_game_events.html#a2712d503dade12e1339da59d781e181e

but i didn't find anything usable.  I also googled :) !

I am just trying write or maybe improve saves syncer. And this is first time, when i am trying to work with KSP API. 

Thank you for any advice, have a nice day :wink:

jozef

Link to comment
Share on other sites

Welcome!

The API docs you've been looking at are a little old. I'm not sure if they've been updated for KSP 1.1. http://docuwiki-kspapi.rhcloud.com/ is a much nicer resource.

think you can do it by creating a class that derives from MonoBehaviour, and specifies the KSPAddon attribute to load at the main menu and has the once attribute set to true - ie, it'll persist for the entirety of the game. In theory, that means that class's OnDestroy() method will be called when the game is shutting down. Something like this:

[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class SaveSyncer : MonoBehaviour
{
  void OnDestroy()
  {
    // Do save file finagling here
  }
}

I haven't actually tested this, though. :)

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...