Godot: Invalid type in built-in function 'dict2inst'. Cannot convert argument 1 from Nil to Dictionary.

Created on 26 Nov 2018  路  11Comments  路  Source: godotengine/godot

I'm trying to load resources dynamically. It works normally on the computer, but on android the following error occurs:

Invalid type in built-in function 'dict2inst'. Cannot convert argument 1 from Nil to Dictionary.

I'm trying to load some Curve2D exported earlier. Here is the code:

extends Node

var paths = []

const path_dir = "res://paths/"

func _ready():
    load_paths()
    pass

func random_path():
    return paths[randi() % paths.size()]

func load_paths():
    var dir = Directory.new()
    dir.change_dir(path_dir)
    dir.list_dir_begin()

    var path_file = dir.get_next()
    var path
    while path_file != "":
        if dir.current_is_dir():
            pass
        else:
            print("loading: " + path_dir + path_file)
            path = load(path_dir + path_file)
            if path && path is Curve2D: #error occours here
                paths.append(path)

        path_file = dir.get_next()
core

All 11 comments

For some reason you are getting a null reference, without a full (but minimal) example will be hard to understand the problem.

Also, does it run on desktop? (not in editor)
If whatever is in "paths" was not exported, it will fail on desktop too.

Actually, exporting to desktop error occurs as well...

Here's the scenario:

  • I created a scene with a Path2D;
  • In this Path2D I created a Curve2D and saved in the paths folder (I did some other Curve2D)
  • In the Script that I posted above I am loading these Curve2D dynamically and adding them into an Array. So I can set random Curve2D in my Path2D

but the error ocours...

Obs.:
The script is a autoload script.

Then maybe the curve resources are not being exported, export as a zip and look at the contents.

I exported as zip and the features are being exported. I also tried deleting the export setup and rebuilding, but the problem was not solved

edited OP to show better GDscript

I downloaded the installer through the website (version 3.0.6) and exported to android without any problems.
I think it's some version 3.1 bug. I imagine it's related to the Export Template.

That's why the issue template asks for your Godot version...

What exact Godot version are you using, and do you have matching export templates? You need to use templates built from the same commit as your editor.

I'm using 3.1 with the correspondent export template. I download by the tool.

What 3.1? 3.1 is in alpha state, it's not a stable version. There are dev snapshots published (alpha 1 and alpha 2), or nightly builds, or self-compiled builds. The templates downloaded through the templates manager are for the alpha 2 snapshot, and can only be used with alpha 2.

Ok. I clone version 3.0.6 and am using it.

@EmanuelOzorio was your issue fixed?

Was this page helpful?
0 / 5 - 0 ratings