Seanba / SuperTiled2Unity

Imports Tiled files to Unity. Better than regular Tiled2Unity.
MIT License
656 stars 84 forks source link

Unable to access SuperTiled2Unity Namespace in Visual Studio. #194

Closed Suspicious-Cloud closed 2 years ago

Suspicious-Cloud commented 2 years ago

I'm trying to access my custom tile properties using SuperTiled2Unity.SuperTile. However, I am unable to access SuperTiled2Unity's namespace / functions in my code. When I add, "using SuperTiled2Unity" to the top of my script, it gives me an error, as is seen in my attachment. Other than not being able to access the namespace in code, the plugin works perfectly in Unity!

I've tried reinstalling the latest version, "SuperTiled2Unity.1.10.3", but it doesn't fix the problem. (I'm using Unity 2021.1.22.f1 Personal). I have also moved the SuperTiled2Unity folder to my Plugins folder in Unity Assets.

I also tried installing "SuperTiled2Unity.1.1.7", and this version did allow me to access the namespace, but gave a few warnings in the Unity Console.

I'm trying to get results similar to this: https://github.com/Seanba/ST2U_TileProperties

devenv_fKDZC3QBoZ

Seanba commented 2 years ago

Hi there, @Suspicious-Cloud. It sounds like your class you are trying to reference the SuperTiled2Unity namespace from is part of an assembly definition. That assembly definition (an .asmdef asset) will need to add the SuperTiled2Unity reference. image

Hope that helps, Sean

Suspicious-Cloud commented 2 years ago

Hi Sean, Thank you for your help. I'm not sure that this is the problem, since the only Assembly Defs I have in my project are the ones included in the SuperTiled2Unity folder. Also, when I check the assembly information of my script, it says it is using the "Assembly-CSharp.dll". I also tried creating an Assembly Def and doing what you suggested, but it still didn't seem to fix my issue.

Unity_31UuRhcY7b

I just tried creating a new project and importing SuperTiled2Unity and it worked fine. So it's likely a problem on my end, not with your software. I think what I may have to do is create a new project and migrate my current project to that new project. Unfortunately, I have no clue what is causing this issue that seems to only be with SuperTiled2Unity.

Also, sorry if this isn't the place to ask for help with your software. I tried to find a forum to ask for help, but was unable to find one.

Thanks again!

Seanba commented 2 years ago

Hi again, @Suspicious-Cloud. This is a good place to ask questions like this. It could be that your C# projects need to be recreated.

Try going to Edit -> Preferences... and select the External Tools option. There you should see a button to Regenerate project files.

image

Suspicious-Cloud commented 2 years ago

Hey Sean, I just tried your suggestion and my problem is still persisting, unfortunately. I'm not sure what I could've changed in my project, since it's a fairly new project. I was able to move my project to a new unity project and everything seems to be working now. However, I wish I knew what was causing my issues so I could prevent it in the future.

Thank you.

Seanba commented 2 years ago

One last thing to try is close Unity, delete your Library folder, and then re-open your project. That will force Unity to re-import everything which sometimes fixes up weird side-effects.

If that doesn't work you can email me your project at sean@seanba.com

Suspicious-Cloud commented 2 years ago

That didn't fix it either. However, I was just copying my broken project folder to send it. I opened that copied project and it was working! I have no idea why copying my project fixed the problem. Maybe it's a bug with the Unity version I'm using? My original project is still having this problem, but when I open my copied version, it works fine.

devenv_vxfX1EfXXX

Seanba commented 2 years ago

For some reason your *.csproj files were (re)created with the wrong references and dependencies. The only other way I can think to resolve this is to go to your project directory (the folder with Assets, Library, ProjectSettings , etc. in it).

From there delete all *.csproj, *.csproj.user, and *.sln files. These files will be recreated for you in Unity if you double click on one of your C# files (from within Unity). That launches Visual Studio, recreating any missing files that are needed.

If that doesn't fix things up for you then it must some bug within Unity that, somehow, fixes itself up when copying the project around. It's really weird.