#Automatically generated Class Name associated with script being added to ResourceLoader file string

29 messages · Page 1 of 1 (latest)

drowsy sequoia
#

Hi ya'll! I'm having an issue loading scenes in Godot 4.2 with C# using ResourceLoader.Load<PackedScene>(ResourcePath) I'm passing it the scene to load from the scenes path via a string as such public string ResourcePath = "res://Spells/MeleAttack.tscn"; and I'm getting this error:

ERROR: Cannot instance script because the associated class could not be found. Script: 'res://Spells/MeleAttack.tscn::CSharpScript_xusnu'. 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).```

the scene isn't being loaded because of the he automatically generated class name associated with the script attached to the scene `CSharpScript_xusnu` Am I attempting to load the scene incorrectly or is this a bug with Godot Mono C#?
wooden elm
#

Have you confirmed what it told you to check about your script name?

drowsy sequoia
#

My tree:

.
├── Collectable.cs
├── GameManager.cs
├── GhostPlayer.cs
├── GhostPlayer.tscn
├── Interactable.cs
├── InterfaceManager.cs
├── JumpEffects.cs
├── JumpEffects.tscn
├── MagicController.cs
├── MagicPotion.cs
├── MagicPotion.tscn
├── MainMenu.cs
├── MainMenu.tscn
├── PlayerController.cs
├── Readme.md
├── RespawnPoint.tscn
├── SeeSharpLearning.csproj
├── SeeSharpLearning.sln
├── Spell.cs
├── Spells
│   ├── MeleAttack.cs
│   └── MeleAttack.tscn
├── Spikes.cs
├── icon.svg
├── icon.svg.import
├── player.tscn
├── playerTestScene.tscn
└── project.godot

I double checked the name and case of the file in Godot as well. I'm hard coding the string of the file path and it's still looking for the file with the generated class name not the actual class name. File name and class name are the same as the scene name spelling and case.

wooden elm
#

What's in the script?

drowsy sequoia
#

Not much right now, I'm just trying to get it to work first then add functionality```using Godot;
using System;

public partial class MeleAttack : Spell
{
public AnimatedSprite2D animatedSprite;
public string ResourcePath = "res://Spells/MeleAttack.tscn";

public override void _Ready()
{
    animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
    animatedSprite.Play("Attack");

}
public override void _Process(double delta)
{
}

public override void SetUp(bool faceDirection)
{
    animatedSprite.FlipH = faceDirection;
}

public override void CastSpell(bool faceDirection)
{
    GD.Print("Casting MeleAttack");

}

public override string LoadResourcePath()
{
    return ResourcePath;
}

public void _on_area_2d_body_entered(Node body)
{
    throw new NotImplementedException();

}
public void _on_animated_sprite_2d_animation_finished()
{
    // if (animatedSprite.Animation == "Attack")
    //     QueueFree();
}

}

#

My controller is attempting to load the scene and I can paste it as well if that is helpful.

wooden elm
#

Have you somehow made the script a built-in script?

drowsy sequoia
#

I don't know. I'll look into that though. Have a quick way to see if I did that?

wooden elm
#

see if clicking the script icon on the node opens the correct file

#

Or see if the script is embedded in the tscn file

drowsy sequoia
#

Yes the correct script is opened when clicking the icon and the correct file/script is also embedded.

wooden elm
#

What do you mean it's embedded?

#

Is the script content actually in the tscn file?

drowsy sequoia
#

When clicking the icon the correct script is opened as well as the correct file is associated with the scene as in the screenshot. Thats what I meant. Sorry if not clear

#

I was attempting to use the same languaging as you saying embedded.

wooden elm
#

What does Spell extend?

drowsy sequoia
#

Node2D```
using Godot;
using System;

public abstract partial class Spell : Node2D
{

public bool facingDirection;
[Export]
public int DamageAmount;
[Export]
public float ManaCost;
[Export]
public int Speed;
public abstract void CastSpell(bool faceDirection);
public abstract string LoadResourcePath();
public abstract void SetUp(bool faceDirection);

}

#

thats the extent of the file

wooden elm
#

Don't really have any more guesses, sorry. Open up your tscn file in a text editor and look for anything unusual

#

Maybe try a different script in this scene?

drowsy sequoia
#

I'll try regenerating the script and starting over. I did open the tscn file in my editor and saw this [sub_resource type="CSharpScript" id="CSharpScript_xusnu"] It's the same string that was being loaded with the file string. I'm not certain what it is but no other tscn file in my project has a similar line.

wooden elm
#

Is your script code embedded in the tscn file?

#

It's weird to have a C# script as a sub_resource, it should I think always be ext_resource

drowsy sequoia
#

I completely removed the script and scene and started over making sure to generate the script from the Godot editor. the same type="CSharpScript" is generated for some reason

#

Also it's strange that when I generated the script the embedded script as shown in the Godot editor showed the tscn file and NOT the .cs file that was just created

wooden elm
#

That's what I was asking about

#

That's why I asked whether clicking the script icon opens the correct file

#

How are you attaching the script?

drowsy sequoia
#

through the Godot editor this time . I may have just created a .cs file before and that's causing some funkyness.