Turn nodes to generic?

Hi, I have a simple scripts that I’m using in a tactic game that uses nodes for pathfinding and other purposes, right now the node has a reference to its GameObject tile, and I want to get rid of this to make them as generic as possibile. This is my simple script:

public class Node
{
public List neighbours;
public GameObject tile;
public int x;
public int y;

public Node()
{
    neighbours = new List<Node>();
}

}

If I simply turn “GameObject” to object then I can’t use GetComponent, which rn I use to check if there’s a unit on and to check if the tile is in the current path.

How do I make them generic?
Or at least is there a way to access GetComponent even if it’s an object?

Many thanks!

Sorry but this makes no sense. What kind of “objects” you want to store in the “tile” variable anyways? If it’s not a gameobject you can’t call GetComponent on it anyways even when you cast the object to GameObject.

If you declare the “tile” variable as “object” like this:

public class Node
{
    public object tile;
}

You can try to cast it to a gameobject like this:

Node someNode;

// [ ... ]
GameObject go = someNode.tile as GameObject;
if (go != null)
{
    go.GetComponent< ... >();
}
else
{
    // tile is not a gameobject or has been destroyed
}