Imported Package not being recognized in Unity or VS2019

Hi,

I have been working for two days to try and install a .unitypackage in Unity. The package is PlayFab. No matter what I seem to do I keep getting this:

error CS0246: The type or namespace name 'PlayFab' could not be found (are you missing a using directive or an assembly reference?).

The package install seemed to go great according to Youtube videos and their own manual.

But, I cannot use the package. Imports are recognized is VS2019 but not in Unity. Any Unity imports give me the above CS0246 error on Unity. It contains the *.asmdef file and should work. I went on the Microsoft PlayFab site and basically after exhausting all their advice in other threads was to “reach out to Unity”. Does anyone have anything that has worked for them when having a problem installing a package in general?

Things I have tried and done:

  • I followed the instructions at this link: Installing the PlayFab SDK for Unity - PlayFab | Microsoft Learn

  • Uninstalled and reinstalled then followed the instructions in the link above again.

  • Updated my VS and .NET. Retried step 2.

  • Updated Unity (now on 2021.3.10f1 LTS). Retried step 2.

  • Restarted my computer between all of these steps.

  • Made sure VS could reference the project. (Project > Add Reference) and made sure that VS could identify PlayFab. Retried step 2

  • Regenerated Project Files for PlayFab in Unity (Edit > Preferences > External Tools > Regenerate Project Files)

  • I just tried repeating the process on my laptop. With the same Unity version and updated VS 2019. Same results! Was really not expecting that one.

  • Deleted the csproj files then reran step 7.

  • Deleted files in the Library folder then restarted Unity.

Really at a loss here. If anyone has any experience with this please let me know. Would love to use and scale project with external packages like PlayFab and am totally at a loss. Thank you.

Unity: 2021.3.10f1 LTS
Visual Studio 2019: 16.11.19
PlayFabSDK: 2.151.220926

Update with Solution. After two days of trying stuff I think I finally got it – lets see if it holds.

For anyone who sees this. Basically, I had to go into my main scripts folder and inspect the scripts.asmdef file in the scripts folder. From there you have a section called Assembly Definition References. You can use the + tab to add a new entry and drag your PlayFab.asmdef file into that. That allows the files in the Scripts assembly to reference PlayFab.

I am baffled why from all the tutorials and stuff this was either overlooked or wasn’t automatically done by Unity. Either way, it seems to be working now.

1 Like

It’s kind of one of those things that you learn along the way. It’s hard to assume whether someone is or isn’t using assembly definition files.

Pretty much with every package you will have to add assembly definition references yourself. Unity can’t do this automatically because A: cyclical references aren’t possible, and B: everything having a reference to everything else would cause domain reloads to be substantially longer.

Just consider it a good lesson into one of the more advanced elements of Unity.

Not arguing the validity of what you’re saying and I appreciate you saying it, it’s been a good lesson for me. But, there is something that about the universality of the solution that is surprising to me.

I’ve watched a few videos and detailed instructions of people getting PlayFab up and running without setting an assembly reference. So, where was the reference to the assembly definition set? Unless there was a conspiracy where all the authors edited that part out of their videos. But, If that were the case you’d expect to see people mention this problem a lot. I wasn’t able to find anything or get any responses (posted this all over the internet) and hence why I made sure to share what I found. Maybe there is a setting between VS2019 and Unity that I am missing?

Either way, I can finally put this two day chapter of my life behind me and have some fun playing with the online elements (it’s been a blast so far).