question

davidshohenry avatar image
davidshohenry asked

error CS0246: The type or namespace name 'PlayFab' could not be found,error CS0246: The type or namespace name 'PlayFab' could not be found

Assets\Photon\PhotonUnityNetworking\Demos\DemoAsteroids\Scripts\Lobby\LobbyMainPanel.cs(6,7): error CS0246: The type or namespace name 'PlayFab' could not be found (are you missing a using directive or an assembly reference?)

I have researched why the namespace PlayFab isn't working in this certain script and I have seen solutions like the external script editor (I am using Visual Studio Community 2022 [17.0.1]) or upgrading Unity version (I am using 2020.1.5f1). I have been using the namespace PlayFab on the other scripts and it is working fine, I have also tried to move the script into the Assembly-CSharp, the namespace PlayFab works but I get some other errors if I move it.

The script that I am having problems with the namespace PlayFab is LobbyMainPanel.cs, this script is only suppose to be in the PhotonUnityNetworking.Demo

The code that I was trying to add in the script is

private void UpdateLeaderboardUsername()
    {
        var request = new UpdateUserTitleDisplayNameRequest()
        {
            DisplayName = PlayerUsername.text
        };
        PlayFabClientAPI.UpdateUserTitleDisplayName(request,
            (result) => { Debug.Log("PlayFab - Score submitted!"); },
        (error) => { Debug.Log("PlayFab - Error occured while submitting the score: " + error.ErrorMessage); });
    } 

When I press Alt and Enter on the PlayFabClientAPII am suppose to be able to add a namespace PlayFab but it wasn't there at all so I copied and pasted using PlayFab; using PlayFab.ClientModels;at the start but I receive errors IDE0005: Using directive is unnecessary and the type or namespace 'PlayFab' could not be found. I have also installed the PlayFab SDK version 2.116.211012. Now when I press on Alt + Enter on PlayFabClientAPI or UpdateUserTitleDisplayNameRequest I can add reference to 'PlayFab' which fixes the error on visual studio so I have no errors however when I am on Unity I still get the same errors which is confusing and I don't know how to fix this.

,

Assets\Photon\PhotonUnityNetworking\Demos\DemoAsteroids\Scripts\Lobby\LobbyMainPanel.cs(6,7): error CS0246: The type or namespace name 'PlayFab' could not be found (are you missing a using directive or an assembly reference?)

I have researched why the namespace PlayFab isn't working in this certain script and I have seen solutions like the external script editor (I am using Visual Studio Community 2022 [17.0.1]) or upgrading Unity version (I am using 2020.1.5f1). I have been using the namespace PlayFab on the other scripts and it is working fine, I have also tried to move the script into the Assembly-CSharp, the namespace PlayFab works but I get some other errors if I move it.

The script that I am having problems with the namespace PlayFab is LobbyMainPanel.cs, this script is only suppose to be in the PhotonUnityNetworking.Demo

The code that I was trying to add in the script is

<code>private void UpdateLeaderboardUsername()
    {
        var request = new UpdateUserTitleDisplayNameRequest()
        {
            DisplayName = PlayerUsername.text
        };
        PlayFabClientAPI.UpdateUserTitleDisplayName(request,
            (result) => { Debug.Log("PlayFab - Score submitted!"); },
        (error) => { Debug.Log("PlayFab - Error occured while submitting the score: " + error.ErrorMessage); });
    }

When I press Alt and Enter on the am suppose to be able to add a namespace PlayFab but it wasn't there at all so I copied and pasted using PlayFab; using PlayFab.ClientModels;at the start but I receive errors IDE0005: Using directive is unnecessary and the type or namespace 'PlayFab' could not be found. I have also installed the PlayFab SDK version 2.116.211012.

Now when I click on the PlayFabClientAPI or UpdateUserTitleDisplayNameRequest I add referene to 'PlayFab' when on the visual studio there are no errors found but when I save it and go back to Unity I still get the same error even though visual studio says there are no errors found

apisunity3dLeaderboards and Statisticsphoton
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

According to your description, you have installed the PlayFab Unity SDK in your project. Did you follow our documentation - Installing the PlayFab SDK for Unity - PlayFab | Microsoft Docs to download and install the PlayFab Unity SDK for your project correctly? For clarification, the C# PlayFab SDK does not apply to Unity, if you followed this documentation - C# PlayFab SDK - PlayFab | Microsoft Docs to install the C# SDK for your Unity project, it may return the errors.

Besides, if you use the Visual Studio as the IDE of your Unity project, we suggest you follow the Unity documentation - Unity - Manual: Visual Studio C# integration (unity3d.com) to select the Visual Studio as the [External Script Editor].

If you have followed the above steps to re-set up your project, but the issue still exists. You can try to create a new project, import the Photon sample and PlayFab SDK correctly, then run your project again.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JayZuo avatar image JayZuo ♦ commented ·

From my experience, set the [External Script Editor] and then "Regenerate project files" in Unity Preferences will resolve this isseu.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.