godot: Can't assign nodes to exported array


Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.


Godot version

Godot 4.0 alpha 11

System information

Solus OS and Windows

Issue description

Can’t assign nodes to an exported array of node pointers

https://user-images.githubusercontent.com/61121689/178321358-fe05eec9-17ab-4d94-ac87-f87b1e059b97.mp4

Steps to reproduce

  1. Export an array of node pointers (@export var node_pointer_array: Array[Node2D])
  2. Try to assign an element to the array on the editor
  3. Element will not be assigned

Or: check out the minimal reproduction project below

Minimal reproduction project

export array of node pointers.zip

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 46
  • Comments: 34 (9 by maintainers)

Most upvoted comments

A good workaround would be to leverage the new array functions.

@export var switches: Array[Switch3D]

would become

@export var switch_nps: Array[NodePath]
@onready var switches = switch_nps.map(get_node)  # feels hacky but works, not in editor though!

The PR which fixed this issue (referenced above, #73256) was merged in the master branch for Godot 4.1, and this happened after the 4.0.2 release, so it’s expected that you still experience the issue in that version.

It may be cherry-picked for 4.0.4 (not for 4.0.3, as we’re still ironing out issues in the master branch).

This is a relatively big issue for 4.0 if you ask me, it’s got a lot of use cases and should definitely be fixed before 4.0 gets released imo.

should definitely be fixed before 4.0 gets released imo.

While it is annoying and limiting, it’s also not critical. This is not something inherently broken and not a regression, just two new features interacting and having issues. Issues in new features are to be expected from the first x.0 release, but we should be able to fix this in a patch release, i.e. 4.0.x. The fix is almost ready, so it shouldn’t take long. We prefer not to take it in now because it touches on the core parts of the engine, and a mistake in that can create massive regressions, so it’s better not to risk it at this point.

Present in beta 10 also

4.0.1 can be out very shortly, but it’s mostly going to be focused on critical regressions not found/not reported before 4.0-stable. Fixes that we wished to have in 4.0 but decided to err on the side of caution are likely to be included in releases after that. The timeline around March is hard to tell due to GDC.

Still an issue in Beta 8. Also applies to custom node types as well.

I tried to do this not knowing it was even possible and ran into this issue. Cool feature hope to see it soon. Sorry for jumping on the dogpile but wanted to participate on godot github somehow 🤣

Temporary workaround: group all the nodes you want to assign under one parent node, then have your script export a single node and iterate over its children on _ready, adding them to the original array.

This is indeed fixed in Godot 4.1 dev 3, however, it still does not work if you have @Tool in your GDScript file. The same bug occurs as prior to the fix, but only if you have @Tool.

Sorry to disappoint, but no (at least not yet). Unfortunately at this point I don’t know much about editor side of things, but the issue is easily reproduced and common, so I hope that it will be fixed in not-so-distant future.

The PR which fixed this issue (referenced above, #73256) was merged in the master branch for Godot 4.1, and this happened after the 4.0.2 release, so it’s expected that you still experience the issue in that version.

It may be cherry-picked for 4.0.4 (not for 4.0.3, as we’re still ironing out issues in the master branch).

Found it fixed in Godot_v4.1-dev2. https://downloads.tuxfamily.org/godotengine/4.1/dev2/ Thank you, for help

A good workaround would be to leverage the new array functions.

That was the obvious thing to try, but did not work for me immediately. This error was in the console.

  Attempted to set a variable of type 'NodePath' into a TypedArray of type 'Object'.
  core/variant/array.cpp:413 - Condition "!_p->typed.validate(value, "set")" is true.

I had to restart the editor to make it work.

Godot version 4.0.2.stable.

Godot 4.0.1. In the console you can see that nodes are added to the array, but in the inspector itself the list is not displayed.

Still an issue in beta 12.

Edit: still an issue in beta 13 (see #71603).