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

GDScript export of C# class not working #79727

Closed
wilfredjonathanjames opened this issue Jul 20, 2023 · 6 comments
Closed

GDScript export of C# class not working #79727

wilfredjonathanjames opened this issue Jul 20, 2023 · 6 comments

Comments

@wilfredjonathanjames
Copy link

Godot version

4.1.1-mono

System information

MacOS 12.3

Issue description

When I do this:

extends Node

const InkStory = preload("res://addons/GodotInk/Src/InkStory.cs")

@export var story: InkStory

InkStory is of type CSharpScript, and the editor shows

image

This prevents me from narrowing the export, because I can use a Resource instead, but I can't verify that resource is the correct type. I'm left with duck typing and an export interface that accepts any resource in my project.

I know that this export would work in C#, so this appears to be an edgecase when loading C# classes into GDScript.

Steps to reproduce

  1. Create a C# script with a class in it, or Import the ink addon.
  2. Create a GDScript with the contents:
extends Node

const MyType = preload("res://path/to/csharp_script.cs") # change to the correct C# script path

@export var specific_resource: MyType

Minimal reproduction project

@AThousandShips
Copy link
Member

AThousandShips commented Jul 21, 2023

Does this work with global classes, exports are restricted to global classes I believe, see here

Can you confirm that this works with a GDScript script loaded in the same way, i.e. without class_name?

Edit: If you can confirm that this also doesn't work with GDScript (as I assume) this is instead a documentation issue and should be made more clear

@VargaDot
Copy link

VargaDot commented Jul 21, 2023

I tried reproducing the bug with global class

using Godot;
using System;

[GlobalClass]
public partial class script : Node
{
    
}

const ScriptPath = preload("res://script.cs")

@export var thing: ScriptPath

Same thing
image

@AThousandShips
Copy link
Member

AThousandShips commented Jul 21, 2023

Just use the name, script and try, though you should name it something safe, as script is reserved on objects

@paulloz
Copy link
Member

paulloz commented Jul 23, 2023

Hello, I maintain the linked addon.
I haven't moved to [GlobalClass] yet, since it is very recent. That's on my roadmap, though.

For now, you should still be able to export from GDScript as a simple resource. Duck typing will ensure everything from InkStory is still accessible anyway. There is a dedicated page about interoperability on our wiki: https://github.com/paulloz/godot-ink/wiki/Interop-with-GDScript

@export var story : Resource

# For instance:
if story.GetCanContinue():
    var current_text = story.Continue()

@paulloz
Copy link
Member

paulloz commented Sep 17, 2023

That's on my roadmap, though.

Just as a heads-up, this is now the case in our v1.1.0.

@raulsntos
Copy link
Member

Closing as this should be fixed now with the latest version of the addon.

@akien-mga akien-mga added this to the 4.3 milestone Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants