reload_current_scene() return value

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

Hello! When I use the method “get_tree().reload_current_scene()” I get the following warning:

The function 'reload_current_scene()' returns a value, but this value is never used.

What does this method return?

:bust_in_silhouette: Reply From: jgodfrey

So, it is just that, a warning. Really, Godot is telling you that the method reload_current_scene() returns a value (in this case, an Error code indicating whether the call succeeded or not) that you are not using in your code.

While you don’t have to use the return value, it’s just telling you that there is a return value that you could be using. If you don’t want to use the value, and you don’t want to see the warning, you can ignore it by:

  • Select the small warning icon just below your source code
  • Click the “ignore” link on the specific warning you want to ignore.

But, you can also choose to do nothing as the warning doesn’t hurt anything.

Edit: I just noticed you’re asking what the method returns. There’s no better place to find that out than the documentation. It’s an Error enum value. See here for details:

Thanks for the answer! The thing is that it’s kinda annoying to have this warning, so I’m trying to figure it out what to do since I have no variable to receive the value of reload_current_scene()

Rubin | 2020-10-20 01:58

So, you can just create a variable to store the value in…

var result = get_tree().reload_current_scene()

However, then Godot will complain that you have a local variable declared that’s not used. To mitigate that, prefix the variable name with an underscore. So, the final solution is this:

var _result = get_tree().reload_current_scene()

jgodfrey | 2020-10-20 03:19

Thanks for the answer! I decided to print the return value.

Rubin | 2020-10-21 02:55