0 votes

Is there a way to test if a resource exists before calling load()? For a practical use case, consider a load_face() function:

func load_face(name: String)
  ears_resource = load("res://%s/ears.png" % name)
  nose_resource = load("res://%s/nose.png" % name)
  eyes_resource = load("res://%s/eyes.png" % name)
  mouth_resource = load("res://%s/mouth.png" % name)
  beard_resource = load("res://%s/beard.png" % name)
  moustache_resource = load("res://%s/moustache.png"  % name)

Calling load_face("debbie") loads Debbie's features from the corresponding folder, and her beard and moustache resources are null which all makes sense. But -- this results in numerous Resource file not found errors being logged because you asked Godot to load a non-existent beard and moustache resource.

Is there some way to maintain this design without printing out errors?

asked Apr 3 in Engine by Poobslag (62 points)

1 Answer

0 votes
Best answer

I think you want the ResourceLoader.exists() method.

answered Apr 3 by jgodfrey (5,706 points)
selected Apr 3 by Poobslag

Thanks, that's exactly what I need!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.