Interface Issue, can't cast (C#)

Godot Version

4.2.1

Question

I’m having issues with casting GodotObjects into my interface.

interface

namespace yume2kkiremake
{
public interface IInteractable
{
void Interact();
}
}

… player .cs …
private void CheckForInteractable()
{
if (rayCast.IsColliding())
{
Variant collider = rayCast.GetCollider();
GodotObject Interactable = (GodotObject)collider.Obj;
if (Interactable != null)
{
IInteractable interactable = Interactable as IInteractable;
if (interactable != null)
{
interactable.Interact();
}
else
{
GD.Print(“Collider is not interactable.”);
}
}
}
}

I was creating an interact feature for my player, but after making it work, i ran into an issue, after making another interactable, it wasn’t able to be casted. after looking everywhere I made a clone of the script that did work, yet it still failed to cast.

Interact Script of object

using Godot;
using System;
using yume2kkiremake;

public partial class Fd : StaticBody2D, IInteractable
{
public void Interact()
{
GD.Print("Scene TP Requested: ", GetMeta(“SceneName”));
}
}

(another but ‘Fd’ instead of ‘Teleport’)

Can someone help me with this?
I’m simply switching the script of the node between the two scripts, one succeeds in the cast (teleporter), and one doesn’t (fd).

Solved: Changed name of cs that wasn’t able to be cast, weird how this is required, but it works.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.