C# Script Loading Issue in Android with Jetpack Compose Integration

Godot Version

4.3.0.stable

Issue Description

I’m encountering an issue where Godot 4.3 fails to load C# scripts when running in an Android app with Jetpack Compose integration, while GDScript files in the same directory load perfectly fine.

Environment

  • Godot 4.3
  • Android with Jetpack Compose
  • Running in a GodotFragment within a Compose AndroidView

Error Messages

USER ERROR: Could not load global script cache.
   at: get_global_class_list (core/config/project_settings.cpp:1226)

USER ERROR: No loader found for resource: res://scripts/components/Sphere.cs (expected type: Script)
   at: *load (core/io/resource*loader.cpp:291)

USER ERROR: res://scenes/levels/Init.tscn:17 - Parse Error: [ext_resource] referenced non-existent resource at: res://scripts/components/Sphere.cs
   at: *parse*ext_resource (scene/resources/resource_format_text.cpp:159)

Project Structure

Both scripts are in the same directory:

  • res://scripts/components/Sphere.cs
  • res://scripts/components/sphere_spin.gd

And the inclusion of the godot project in android looks like the following:

app/src/main/assets/
├── Shinmamoru.csproj
├── Shinmamoru.sln
├── icon.svg
├── icon.svg.import
├── project.godot
├── scenes
│   └── levels
│       └── Init.tscn
└── scripts
    └── components
        ├── Sphere.cs
        └── sphere_spin.gd

Scene File (scene.tscn)

[gd_scene load_steps=3 format=3 uid="uid://ca3xn0dao0t12"]

[ext_resource type="Script" path="res://scripts/components/Sphere.cs" id="1_qqhde"]
[ext_resource type="Script" path="res://scripts/components/sphere_spin.gd" id="2_j1boc"]

[node name="Node3D" type="Node3D"]

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
script = ExtResource("1_qqhde")

[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.329488)

[node name="CSGSphere3D" type="CSGSphere3D" parent="."]
transform = Transform3D(0.0601282, 0.229643, -0.124164, 0, 0.255315, 0.119137, 0.232683, -0.0593427, 0.0320857, 0, 0, 0)
radius = 0.215404
script = ExtResource("2_j1boc")

Android Integration Code

@Composable
fun GodotView(modifier: Modifier = Modifier) {
    Scaffold {
        Column(modifier = Modifier.padding(it)) {
            Text(text = "Hello from Jetpack Compose!", fontSize = 30.sp, color = Color.Yellow)

            AndroidView(
                factory = { context ->
                    FrameLayout(context).apply {
                        layoutParams = ViewGroup.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT,
                            ViewGroup.LayoutParams.MATCH_PARENT,
                        )

                        id = View.generateViewId()

                        val fragmentTransaction =
                            (context as FragmentActivity).supportFragmentManager.beginTransaction()

                        fragmentTransaction.replace(id, GodotFragment())
                        fragmentTransaction.commit()
                    }
                },
                modifier = Modifier
                    .fillMaxSize()
                    .height(400.dp),
            )

            Text("I mean this text should now prevent the GodotFragment from being fullscreen")
        }
    }
}

Expected Behavior

Both the C# script and GDScript should load properly when the scene is loaded in the GodotFragment.

Actual Behavior

  • The GDScript loads and executes correctly
  • The C# script fails to load with the errors shown above
  • The error suggests the script loader for C# is not being initialized properly

Questions

  1. Is there something specific needed for C# script loading in Android/Compose integration?
  2. Could this be related to the way the GodotFragment is initialized?
  3. Are there any additional steps needed to enable C# script loading in this context?

Any help or guidance would be greatly appreciated!