Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • Feature Requests /
avatar image

Claire Rochelmeyer suggested an idea · Mar 09 at 01:52 AM · unity3d

Unity PlayFabEdEx asset recreation and general improvements

This was reported in bugs and I still consider this a bug (should be fixed regardless of votes as it hinders production). See thread here

The main issue being is moving the PlayFabEdEx plugin out of the root assets folder (something that would be done in most if not all projects to keep folder structure manageable in large projects) causes the PlayFabEditorPrefsSO asset to be continuously recreated when opening the project or when Unity refreshes the Asset Database. This unhooks the original asset that has the login info from the Editor Window, and the newly created asset must first be found and deleted before the window locates the correct asset.

This is due to the Resources.LoadAll call failing while Unity is refreshing assets, something that happens each time the project is opened, importing new assets, or changing source control branches.

My initial changes only solved the issue when the project is initially opened, and still caused the issue when assets were being refreshed. The initial changes were to "tag the asset with a Label and search the AssetDatabase for that Label when necessary. This seems to be more reliable than loading Resources as it works when the project is opened in editor. The changes to the Instance property in PlayFabEditorPrefsSO are as follows:"

public static PlayFabEditorPrefsSO Instance
{
	get
	{
		if (_instance != null) return _instance;

                var guids = AssetDatabase.FindAssets("l:PlayFabEditorPrefs");
                if (guids.Length > 0)
                {
			_instance = AssetDatabase.LoadAssetAtPath(
                        	AssetDatabase.GUIDToAssetPath(guids[0]), 
                        	typeof(PlayFabEditorPrefsSO)) as PlayFabEditorPrefsSO;
                }
                if (_instance != null) return _instance;

                if (!Directory.Exists(Path.Combine(Application.dataPath, "PlayFabEditorExtensions/Editor")))
		{
			Directory.CreateDirectory(Path.Combine(Application.dataPath, "PlayFabEditorExtensions/Editor"));
		}

                _instance = CreateInstance<PlayFabEditorPrefsSO>();
                AssetDatabase.CreateAsset(_instance, "Assets/PlayFabEditorExtensions/Editor/PlayFabEditorPrefsSO.asset");
                AssetDatabase.SetLabels(_instance, new []{"PlayFabEditorPrefs"});
                AssetDatabase.SaveAssets();
                Debug.LogWarning("Created missing PlayFabEditorPrefsSO file");
                return _instance;
	}
}

This was a better way of searching the project for an asset rather than relying on the Resources folder, so I still kept these changes after working out the final solution.

The core of the issue was that PlayFabEditorPrefsSO.Instance was being accessed from constructors that were marked with [InitializeOnLoad], specifically trying to access the stored values "curMainMenuIdx", "curSubMenuIdx" and "PanelIsShown" on PlayFabEditorPrefsSO. Other than the naming inconsistencies, this presented a different issue in the way of source control issues, where simply navigating the PlayFab editor window (without making field changes) causes the asset to override these values, causing unnecessary differences in source control. These such serialized fields shouldn't be recorded in a scriptable object that isn't gitignored.

Incidentally, by removing the serialized fields removes the need of loading the asset instance from the AssetDatabase during a refresh, fixing the initial issue. As the formerly serialized fields do not need to be shared to other team members, I used EditorPrefs to save/set the values instead.

Added to the "menu and helper methods" region of PlayFabEditor:

private const string PanelShownKey = "PlayFabEdEx-PanelShown";

public static bool PanelShown
{
	get => EditorPrefs.GetBool(PanelShownKey, false);
	set => EditorPrefs.GetBool(PanelShownKey, value);
}

private const string MainMenuIndexKey = "PlayFabEdEx-CurrentMainMenuIndex";

public static int CurrentMainMenuIndex
{
	get => EditorPrefs.GetInt(MainMenuIndexKey, 0);
	set => EditorPrefs.SetInt(MainMenuIndexKey, value);
}

private const string SubMenuIndexKey = "PlayFabEdEx-CurrentSubMenuIndex";

public static int CurrentSubMenuIndex
{
	get => EditorPrefs.GetInt(SubMenuIndexKey, 0);
	set => EditorPrefs.SetInt(SubMenuIndexKey, value);
}

As these were the only values the PlayFabEditor was trying to access from the scriptable object, by moving the stored values out of it, it's no longer trying to create a new instance every time assets get updated.

On another point, the Unity plugin for PlayFab really needs an overhaul and to fix compile warnings for deprecated web request functions in Unity 2020+. Again this a bug, not a feature request, we shouldn't have to wait for people to search up and vote for a forum post for you to keep your plugin up to date and usable.

thub.nodes.view.add-new-comment
Claire Rochelmeyer

People who like this

1 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 comment

· Add your reply
avatar image

Justin Heasman commented · Mar 15 at 10:06 AM

We are getting this bug too. It is really annoying.

thub.nodes.view.add-new-comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Your Opinion Counts

    We would love to know what you need. Submit your ideas and upvote others to help us prioritize.

    Sign in to post a new idea

    Follow

    Follow This Idea

    No one has followed this yet.

    Related Ideas

    Silent Login for Google Play Games Services on Android

    Tutorial on how to integrate an existing Azure active directory with Playfab for account log in, registration for Unity3D

    Stop editor extensions window opening automatically in Unity

    Calls to depricated features of UnityWebRequest

    Add EntityKey To SharedModels In Unity

    PlayFabMultiplayerManager SendDataMessage with PARTY_SEND_MESSAGE_OPTIONS parameter

    WWW is obsolete in Unity 2018

    Assembly Definitions (.asmdef) to support Unity Package Manager

    Add Sign-in with Apple to the Unity plugin

    Improvement of the add-on "Apple" and PlayFabClientApi for validation of purchases for MacOSX.

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges