godot-visual-script icon indicating copy to clipboard operation
godot-visual-script copied to clipboard

can_instantiate() error while following first 3D game tutorial

Open GottethACluePerchance opened this issue 2 years ago • 1 comments

Godot version

4.1.2 Mono

System information

Windows 11 Home 22H1

Issue description

I'm absolutely new to Godot and just followed the 3D game tutorial on Godot Docs, but cannot run the player.cs script due to the can_instantiate() giving an error saying the CharacterBody3D class can't be found.

Error Message:

E 0:00:00:0730   can_instantiate: Cannot instance script because the associated class could not be found. Script: 'res://player.cs'. Make sure the script exists and contains a class definition with a name that matches the filename of the script exactly (it's case-sensitive).
  <C++ Error>    Method/function failed. Returning: false
  <C++ Source>   modules/mono/csharp_script.cpp:2388 @ can_instantiate()

The .csproj contents were:

<Project Sdk="Godot.NET.Sdk/4.1.2">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
    <GodotProjectDir>$(MSBuildProjectDirectory)</GodotProjectDir>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Godot.SourceGenerators" Version="4.1.2" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
    <PackageReference Include="GodotSharp" Version="4.1.2" />
  </ItemGroup>
</Project>

While the .sln content

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34202.233
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squash the Creeps (3D)", "Squash the Creeps (3D).csproj", "{2C874C92-5724-442C-BB10-7A09E7CD17E3}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		ExportDebug|Any CPU = ExportDebug|Any CPU
		ExportRelease|Any CPU = ExportRelease|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{2C874C92-5724-442C-BB10-7A09E7CD17E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{2C874C92-5724-442C-BB10-7A09E7CD17E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{2C874C92-5724-442C-BB10-7A09E7CD17E3}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
		{2C874C92-5724-442C-BB10-7A09E7CD17E3}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
		{2C874C92-5724-442C-BB10-7A09E7CD17E3}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
		{2C874C92-5724-442C-BB10-7A09E7CD17E3}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {CD9C353F-1E60-4943-B756-5453F1B32648}
	EndGlobalSection
EndGlobal

Yes, I have tried checked several other solutions but all did not fix my problems.

The ones I found were: https://github.com/godotengine/godot/issues/73932 https://github.com/godotengine/godot/issues/71735 https://github.com/godotengine/godot/issues/73932 https://github.com/godotengine/godot/issues/75352

Steps to reproduce

Following the Godot Docs 'Your First 3D game' tutorial up until 'Testing our player's movement' in step 3.

Minimal reproduction project

No response

GottethACluePerchance avatar Oct 27 '23 10:10 GottethACluePerchance

Why are you setting the GodotProjectDir property in the .csproj? And why are you adding the package references to Godot.SourceGenerators and GodotSharp? All of this is included by the Godot.NET.Sdk so you shouldn't need to do it manually.

You didn't include a minimal reproduction project, so I can't know exactly what's causing the issue. However, it seems likely that, like the error says, the player.cs script contains a class that doesn't match the name of the file. Please upload an MRP to make this easier to troubleshoot.

raulsntos avatar Dec 07 '23 15:12 raulsntos