playMaker

Author Topic: How to go about actions with disabled systems between platforms  (Read 1600 times)

autumnboy

  • Junior Playmaker
  • **
  • Posts: 73
How to go about actions with disabled systems between platforms
« on: January 28, 2020, 11:21:38 PM »
Hi
I'm currently creating between Steam and xbox one,
I have some custom steamworks actions that pull up errors when switching to xbox one because the code from steamworks disables itself if not on desktop.

What way could I go about this? Or how could I update the action. I only use these actions in conjunction with Steam.
Playmaker action example:

Code: [Select]

using UnityEngine;
using Steamworks;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("Steamworks.NET - Client")]
    [Tooltip("Gets the Steam ID of the account currently logged into the Steam client. This is commonly called the 'current user', or 'local user'.")]
    public class Steam_GetSteamID : FsmStateAction
    {
        [RequiredField]
        [UIHint(UIHint.Variable)]
        public FsmString steamID;

        public override void Reset()
        {
            steamID = null;

        }

        public override void OnEnter()
        {
            CSteamID ID = SteamUser.GetSteamID();
            steamID.Value = ID.ToString();
            Finish();
        }
    }
}


Steamworks code example:
Code: [Select]
// This file is provided under The MIT License as part of Steamworks.NET.
// Copyright (c) 2013-2018 Riley Labrecque
// Please see the included LICENSE.txt for additional information.

// This file is automatically generated.
// Changes to this file will be reverted when you update Steamworks.NET

#if UNITY_ANDROID || UNITY_IOS || UNITY_TIZEN || UNITY_TVOS || UNITY_WEBGL || UNITY_WSA || UNITY_PS4 || UNITY_WII || UNITY_XBOXONE || UNITY_SWITCH
#define DISABLESTEAMWORKS
#endif

#if !DISABLESTEAMWORKS

using System.Runtime.InteropServices;
using IntPtr = System.IntPtr;

namespace Steamworks {
public static class SteamClient {
/// <summary>
/// <para> Creates a communication pipe to the Steam client.</para>
/// <para> NOT THREADSAFE - ensure that no other threads are accessing Steamworks API when calling</para>
/// </summary>
public static HSteamPipe CreateSteamPipe() {
InteropHelp.TestIfAvailableClient();
return (HSteamPipe)NativeMethods.ISteamClient_CreateSteamPipe(CSteamAPIContext.GetSteamClient());
}

/// <summary>
/// <para> Releases a previously created communications pipe</para>
/// <para> NOT THREADSAFE - ensure that no other threads are accessing Steamworks API when calling</para>
/// </summary>
public static bool BReleaseSteamPipe(HSteamPipe hSteamPipe) {
InteropHelp.TestIfAvailableClient();
return NativeMethods.ISteamClient_BReleaseSteamPipe(CSteamAPIContext.GetSteamClient(), hSteamPipe);
}

/// <summary>
/// <para> connects to an existing global user, failing if none exists</para>
/// <para> used by the game to coordinate with the steamUI</para>
/// <para> NOT THREADSAFE - ensure that no other threads are accessing Steamworks API when calling</para>
/// </summary>
public static HSteamUser ConnectToGlobalUser(HSteamPipe hSteamPipe) {
InteropHelp.TestIfAvailableClient();
return (HSteamUser)NativeMethods.ISteamClient_ConnectToGlobalUser(CSteamAPIContext.GetSteamClient(), hSteamPipe);
}

/// <summary>
/// <para> used by game servers, create a steam user that won't be shared with anyone else</para>
/// <para> NOT THREADSAFE - ensure that no other threads are accessing Steamworks API when calling</para>
/// </summary>
public static HSteamUser CreateLocalUser(out HSteamPipe phSteamPipe, EAccountType eAccountType) {
InteropHelp.TestIfAvailableClient();
return (HSteamUser)NativeMethods.ISteamClient_CreateLocalUser(CSteamAPIContext.GetSteamClient(), out phSteamPipe, eAccountType);
}

/// <summary>
/// <para> removes an allocated user</para>
/// <para> NOT THREADSAFE - ensure that no other threads are accessing Steamworks API when calling</para>
/// </summary>
public static void ReleaseUser(HSteamPipe hSteamPipe, HSteamUser hUser) {
InteropHelp.TestIfAvailableClient();
NativeMethods.ISteamClient_ReleaseUser(CSteamAPIContext.GetSteamClient(), hSteamPipe, hUser);
}

/// <summary>
/// <para> retrieves the ISteamUser interface associated with the handle</para>
/// </summary>
public static IntPtr GetISteamUser(HSteamUser hSteamUser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamUser(CSteamAPIContext.GetSteamClient(), hSteamUser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> retrieves the ISteamGameServer interface associated with the handle</para>
/// </summary>
public static IntPtr GetISteamGameServer(HSteamUser hSteamUser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamGameServer(CSteamAPIContext.GetSteamClient(), hSteamUser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> set the local IP and Port to bind to</para>
/// <para> this must be set before CreateLocalUser()</para>
/// </summary>
public static void SetLocalIPBinding(uint unIP, ushort usPort) {
InteropHelp.TestIfAvailableClient();
NativeMethods.ISteamClient_SetLocalIPBinding(CSteamAPIContext.GetSteamClient(), unIP, usPort);
}

/// <summary>
/// <para> returns the ISteamFriends interface</para>
/// </summary>
public static IntPtr GetISteamFriends(HSteamUser hSteamUser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamFriends(CSteamAPIContext.GetSteamClient(), hSteamUser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> returns the ISteamUtils interface</para>
/// </summary>
public static IntPtr GetISteamUtils(HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamUtils(CSteamAPIContext.GetSteamClient(), hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> returns the ISteamMatchmaking interface</para>
/// </summary>
public static IntPtr GetISteamMatchmaking(HSteamUser hSteamUser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamMatchmaking(CSteamAPIContext.GetSteamClient(), hSteamUser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> returns the ISteamMatchmakingServers interface</para>
/// </summary>
public static IntPtr GetISteamMatchmakingServers(HSteamUser hSteamUser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamMatchmakingServers(CSteamAPIContext.GetSteamClient(), hSteamUser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> returns the a generic interface</para>
/// </summary>
public static IntPtr GetISteamGenericInterface(HSteamUser hSteamUser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamGenericInterface(CSteamAPIContext.GetSteamClient(), hSteamUser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> returns the ISteamUserStats interface</para>
/// </summary>
public static IntPtr GetISteamUserStats(HSteamUser hSteamUser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamUserStats(CSteamAPIContext.GetSteamClient(), hSteamUser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> returns the ISteamGameServerStats interface</para>
/// </summary>
public static IntPtr GetISteamGameServerStats(HSteamUser hSteamuser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamGameServerStats(CSteamAPIContext.GetSteamClient(), hSteamuser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> returns apps interface</para>
/// </summary>
public static IntPtr GetISteamApps(HSteamUser hSteamUser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamApps(CSteamAPIContext.GetSteamClient(), hSteamUser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> networking</para>
/// </summary>
public static IntPtr GetISteamNetworking(HSteamUser hSteamUser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamNetworking(CSteamAPIContext.GetSteamClient(), hSteamUser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> remote storage</para>
/// </summary>
public static IntPtr GetISteamRemoteStorage(HSteamUser hSteamuser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamRemoteStorage(CSteamAPIContext.GetSteamClient(), hSteamuser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> user screenshots</para>
/// </summary>
public static IntPtr GetISteamScreenshots(HSteamUser hSteamuser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamScreenshots(CSteamAPIContext.GetSteamClient(), hSteamuser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> returns the number of IPC calls made since the last time this function was called</para>
/// <para> Used for perf debugging so you can understand how many IPC calls your game makes per frame</para>
/// <para> Every IPC call is at minimum a thread context switch if not a process one so you want to rate</para>
/// <para> control how often you do them.</para>
/// </summary>
public static uint GetIPCCallCount() {
InteropHelp.TestIfAvailableClient();
return NativeMethods.ISteamClient_GetIPCCallCount(CSteamAPIContext.GetSteamClient());
}

/// <summary>
/// <para> API warning handling</para>
/// <para> 'int' is the severity; 0 for msg, 1 for warning</para>
/// <para> 'const char *' is the text of the message</para>
/// <para> callbacks will occur directly after the API function is called that generated the warning or message.</para>
/// </summary>
public static void SetWarningMessageHook(SteamAPIWarningMessageHook_t pFunction) {
InteropHelp.TestIfAvailableClient();
NativeMethods.ISteamClient_SetWarningMessageHook(CSteamAPIContext.GetSteamClient(), pFunction);
}

/// <summary>
/// <para> Trigger global shutdown for the DLL</para>
/// </summary>
public static bool BShutdownIfAllPipesClosed() {
InteropHelp.TestIfAvailableClient();
return NativeMethods.ISteamClient_BShutdownIfAllPipesClosed(CSteamAPIContext.GetSteamClient());
}

/// <summary>
/// <para> Expose HTTP interface</para>
/// </summary>
public static IntPtr GetISteamHTTP(HSteamUser hSteamuser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamHTTP(CSteamAPIContext.GetSteamClient(), hSteamuser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> Exposes the ISteamController interface</para>
/// </summary>
public static IntPtr GetISteamController(HSteamUser hSteamUser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamController(CSteamAPIContext.GetSteamClient(), hSteamUser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> Exposes the ISteamUGC interface</para>
/// </summary>
public static IntPtr GetISteamUGC(HSteamUser hSteamUser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamUGC(CSteamAPIContext.GetSteamClient(), hSteamUser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> returns app list interface, only available on specially registered apps</para>
/// </summary>
public static IntPtr GetISteamAppList(HSteamUser hSteamUser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamAppList(CSteamAPIContext.GetSteamClient(), hSteamUser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> Music Player</para>
/// </summary>
public static IntPtr GetISteamMusic(HSteamUser hSteamuser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamMusic(CSteamAPIContext.GetSteamClient(), hSteamuser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> Music Player Remote</para>
/// </summary>
public static IntPtr GetISteamMusicRemote(HSteamUser hSteamuser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamMusicRemote(CSteamAPIContext.GetSteamClient(), hSteamuser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> html page display</para>
/// </summary>
public static IntPtr GetISteamHTMLSurface(HSteamUser hSteamuser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamHTMLSurface(CSteamAPIContext.GetSteamClient(), hSteamuser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> inventory</para>
/// </summary>
public static IntPtr GetISteamInventory(HSteamUser hSteamuser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamInventory(CSteamAPIContext.GetSteamClient(), hSteamuser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> Video</para>
/// </summary>
public static IntPtr GetISteamVideo(HSteamUser hSteamuser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamVideo(CSteamAPIContext.GetSteamClient(), hSteamuser, hSteamPipe, pchVersion2);
}
}

/// <summary>
/// <para> Parental controls</para>
/// </summary>
public static IntPtr GetISteamParentalSettings(HSteamUser hSteamuser, HSteamPipe hSteamPipe, string pchVersion) {
InteropHelp.TestIfAvailableClient();
using (var pchVersion2 = new InteropHelp.UTF8StringHandle(pchVersion)) {
return NativeMethods.ISteamClient_GetISteamParentalSettings(CSteamAPIContext.GetSteamClient(), hSteamuser, hSteamPipe, pchVersion2);
}
}
}
}

#endif // !DISABLESTEAMWORKS

-Josh

Thrump

  • Playmaker Newbie
  • *
  • Posts: 6
Re: How to go about actions with disabled systems between platforms
« Reply #1 on: January 29, 2020, 09:20:25 AM »
A few options I can think of:
1) have a different fsm per platform
2) skip the state giving you trouble with an action that checks the platform
3) wrap code in Steam_GetSteamID in #if !UNITY_XBOXONE
4) wrap code in Steam_GetSteamID in if (!RuntimePlatform.XboxOne)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: How to go about actions with disabled systems between platforms
« Reply #2 on: January 29, 2020, 09:33:05 AM »
Hi.
I have send a updated version of the steamworks actions i have.

But while writing this i think that you will have missing action issues if you have actions in the scene.

I will update them this weekend, pls bumb me here and on discord if i do not have a update yet by sunday :)

autumnboy

  • Junior Playmaker
  • **
  • Posts: 73
Re: How to go about actions with disabled systems between platforms
« Reply #3 on: January 29, 2020, 07:28:04 PM »
I did try to wrap the code in the actions that disable steamworks check but yes made all my actions just go missing and caused playmaker errors. Only happens while unity is rebuilt to xbox platform settings. Looks like steamworks api just gets disabled and can't find the system.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: How to go about actions with disabled systems between platforms
« Reply #4 on: January 30, 2020, 01:35:13 PM »
Hi.
Indeed the whole steamworks gets disabled when platform is not supported.

i will try in the weekend if i can find a solution.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: How to go about actions with disabled systems between platforms
« Reply #5 on: January 31, 2020, 09:44:26 PM »
With official actions, we try to wrap only the part that's missing in a define, so the action is still present even if it doesn't work.

For example, Unity 2019.3 makes MovieTexture obsolete, so the next Playmaker update will wrap MovieTexture actions like this:

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2020. All rights reserved.

#if UNITY_2018_2_OR_NEWER
#pragma warning disable CS0618 
#endif

#if !(UNITY_SWITCH || UNITY_TVOS || UNITY_IPHONE || UNITY_IOS  || UNITY_ANDROID || UNITY_FLASH || UNITY_PS3 || UNITY_PS4 || UNITY_XBOXONE || UNITY_BLACKBERRY || UNITY_METRO || UNITY_WP8 || UNITY_PSM || UNITY_WEBGL || UNITY_SWITCH)

using System;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Movie)]
#if UNITY_2019_3_OR_NEWER
    // Mark Obsolete but keep parameters
    // so user can convert them to new actions.
    [Obsolete("Use VideoPlayer actions instead.")]
#endif
[Tooltip("Plays a Movie Texture. Use the Movie Texture in a Material, or in the GUI.")]
public class PlayMovieTexture : FsmStateAction
{
[RequiredField]
#if !UNITY_2019_3_OR_NEWER
        [ObjectType(typeof(MovieTexture))]
#endif
public FsmObject movieTexture;

public FsmBool loop;

public override void Reset()
{
movieTexture = null;
loop = false;
}

public override void OnEnter()
{
#if !UNITY_2019_3_OR_NEWER
var movie = movieTexture.Value as MovieTexture;

if (movie != null)
{
movie.loop = loop.Value;
movie.Play();
}
#endif
Finish();
}

#if UNITY_2019_3_OR_NEWER
        public override string ErrorCheck()
        {
            return "MovieTexture is Obsolete. Use VideoPlayer actions instead.";
        }
#endif
}
}

#endif

The action is still there with Obsolete warnings. But you can still see the parameters to see what the action was doing and convert it to a VideoPlayer action.

The key is to wrap only the unsupported parts, not the whole action.