Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Add note about the class name in instantiate error #70210

Merged
merged 1 commit into from
Dec 17, 2022

Conversation

raulsntos
Copy link
Member

Adds a note about the requirement that a C# class name must match the script filename in which the they are defined to the instantiate error.

This should hopefully make the error more user-friendly and avoid issues such as #66419 in the future.

Feel free to suggest a better message, the goal is to mention the common reasons why the associated class was not found:

  • File at the specified path does not exist.
    In case the user attached a script to a Node and then deleted the script without detaching it from the Node.
  • The file exists but it contains no class or the class defined does not match the name of the filename.
  • The script filename and the class name are case-sensitive.
    It seems common for users to define a class such as Player using PascalCase to follow .NET class naming conventions and then name the script player.cs because Godot uses snake_case for filenames by default.

Adds a note about the requirement that a C# class name must match the
script filename in which the they are defined to the instantiate error.
@raulsntos raulsntos added this to the 4.0 milestone Dec 17, 2022
@raulsntos raulsntos requested a review from a team as a code owner December 17, 2022 19:14
@neikeq neikeq merged commit d44d0cc into godotengine:master Dec 17, 2022
@raulsntos raulsntos deleted the dotnet/script-not-found-error branch December 17, 2022 22:54
@avilches
Copy link
Contributor

avilches commented Dec 19, 2022

One of the reason could be the assembly is copied in a different folder than the expected. Maybe something like: "Ensure the assembly is located in X" where X is the expected folder (csproj_folder.godot\mono\tem\bin or whatever). It could sound crazy, but It really happened to me because I had the main csproj folder in a different folder than the solution by mistake.

EDIT: or maybe this scenario (where csproj and godot.project are located in different folder) could throw an error in the dotnet build stage. I can open an issue/proposal with this...

@raulsntos
Copy link
Member Author

@avilches It's no longer possible to move the .csproj, and if the built assemblies don't end up in the right place it would be a bug and not an user error.

If you still think there's a bug, make sure to test with beta 9 that was recently released and may fix it. If you can still reproduce it feel free to open a new issue with more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants