EditorPlugin - How to determine what type of resource a custom resource is?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mordi

I’m trying to add files to a tree inside my editor plugin. So far, it’s working well. I can retrieve a list of all files in the res:// folder, and add them to the tree, just like the native FileSystem does.

I’d like to filter out my tree, so that it only adds my custom AudioEvent resource. I have access to the full path of all my files, but I don’t know how to convert those into something where I can find out what type of resource each file is, since they all have the .tres extension.

Does anyone know how I can achieve this?

:bust_in_silhouette: Reply From: Mordi

Huh, just after asking, I figured out an answer.

var res = load(filepath) as AudioEvent
if res != null:
	print("This is a custom AudioEvent resource")

load() is pretty taxing, so I make sure to do some additional checks before this to make sure I’m not loading all files of the entire project. I check that this is a resource file first, for example. This can be done by checking that the extension is .tres.