Godot 4 | エラーまとめ

2023-11-19Godot 4,Godot 4 基本

Godot 4 | エラーまとめ

ゲームエンジン「Godot 4」を使っている上で、遭遇・確認した事のあるエラーについて主に簡単なミスのエラーを中心にメモとして、まとめています。

確認環境
  • Windows11 22H2
  • Godot v4.1.1

Attempt to call function 'XXX’ in base 'null instance’ on a null instance.

「null」となっているインスタンスやノード情報から関数を呼び出そうとしています。

対象が見つかっていないために関数を呼び出せない状態なので呼び出し先のパスなどを確認する。

var target = get_node("/root/Main/TARGET")
target.XXX()

Blend file import is enabled in the project settings ~

エラー全文
modules/gltf/register_types.cpp:73 – Blend file import is enabled in the project settings, but no Blender path is configured in the editor settings. Blend files will not be imported.

blender のインポートが有効になっているけど、エディター設定で Blender のパスが構成されていないと発生する警告エラー。

blenderを使う予定がなく警告エラーを非表示にしたい場合は「プロジェクト設定」「ファイルシステム」「インポート」にて「blender」を無効にする。

Condition “res != ((HRESULT)0x00000000)" is true. Returning: String()

エラー全文
platform/windows/os_windows.cpp:1607 – Condition “res != ((HRESULT)0x00000000)" is true. Returning: String()

起動時に表示される不明なエラー、現状支障はないけど解決できていない。
Godot エディターの更新待ちになるかもしれません。

Expected indented block after “if" block.

「if」ブロックの後にインデントされたブロックが必要です。

「if」の処理が閉じられていない。
コメントアウトだけなどの場合は「pass」で対応できる。

if visible:
	# visibleがtrueのとき
	pass

Expected statement, found “else" instead.

予期された位置のステートメントに「else」が見つかりました。

「else」のインデント位置がおかしい。
本来は直前の「if」と同階層になる。

if visible:
	# visibleがtrueのとき
	pass
else:
	# visibleがfalseのとき
	pass

Invalid argument for “connect()" function: argument 2 should be “Callable" but is ~

connect()の引数が無効、引数2は「Callable」である必要があります。

Godot 4では、以下のように記述する。

Godot 3.x
button.connect("pressed", self, "_button_pressed")
Godot 4.x
button.connect("pressed", Callable(self, "_button_pressed"))

Invalid set index 'text’ (on base: 'Label (Label.gd)’) with value of type 'int’.

Lavelに表示しようとしているテキストが数値型になっている事が原因で発生するエラー。
str()関数で文字列に変換する。

var int_data = 100
self.text = str(int_data)

Node not found

ノードが見つかりません。

get_node()メソッドほかで指定したパスが違う場合などに発生する。
例えば「root」以下を指定した場合、最初の「/」が足りないなど。

var target = get_node("/root/Main/TARGET")

The parameter “body” is never used in the function ~

_on_area_2d_body_entered()関数内にて引数「body」が利用されていない。

警告エラーなので「body」を使うまでそのままにしておくか、使わない間は「_body」としておく。

func _on_area_2d_body_entered(_body):
	pass

Tween can’t be created directly. Use create_tween() method.

トゥイーンを直接作成することはできません。

Godot 4ではTween.new()は利用できません。
代わりにcreate_tween() メソッドを使用します。

var _tween = create_tween()
	_tween.tween_property(self, "modulate", Color(0,0,0,0), 0.5)
	_tween.play()

Unexpected “Identifier" in class body.

Godot 4.xから「export」「onready」の記述が変更となっているため、3.x系のコードではエラーが発生する。

例えば、4.xでは「$AnimationPlayer」ノードを読み込む際に先頭に「@」を付ける必要があります。

// Godot 3.x
onready var anim = $AnimationPlayer

// Godot 4.x
@onready var anim = $AnimationPlayer

Unexpected “if" in class body.

クラス本体内に予期しない「if」があります。

関数と同じ階層に「if」を記述してしまっている、など。

func _ready():
	if visible:
		# visibleがtrueのとき
		pass