The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes


I am trying to do something with instanced nodes. The instancing code looks something like

var node = []
var node_prefab = load("res://Node.tscn")

func _ready():
    for i in range(x):

Then I change the values with something like this:

func _physics_process(delta):
    for i in range(x):
        node[i].variable = a

The variable in question depends on the node type. When the project runs, the code to assign the variables doesn't work and nothing happens. However, when I check with print(), the correct variables aren displayed. It's like my code is not correctly applying the change to the actual instanced nodes in the scene. What am I doing wrong?

Edit : I realize that some of the variables work. What doesn't work is 6DOF physics joints. According to debug, the variables to set the spring force and the damping and link the joint to the body and wheels are getting passed to the joint, but the joint does nothing. It's supposed to act as a car suspension but it just does nothing.

:Here's a link to the problem

I don't understand what's going wrong. Is it something with joints specifically?

Godot version v3.2.3.stable.official
in Engine by (74 points)
edited by

have you checked if the node in the array and the node added as child are actually the same object?

I just checked the instanced nodes' name and place in the hierarchy and it recieves the correct variables. I don't know what's happening.

does it work if, instead of calling the joint from the array, you call it from the scene tree?
like using get_child(x) or get_node("WhateverNodeName")

2 Answers

0 votes
Best answer

I fixed it, I was doing


I was inputting the path of the node to join from the point of view of the node carrying the scrpt and that's not how it works. I was supposed to input the path from the joint node, like:

by (74 points)
0 votes

I'm not sure if this would work:

func _ready():
    var nodeToAdd : Node
    for i in range(x):
        nodeToAdd = node_prefab.instance()

I had the same problem earlier and I solved adding the nodes to another node (like Spatial in 3D) (which should be a child of the root node) as children, so I can access them using built-in functions, in my code I use for child in scenarioTiles.get_children():

by (255 points)
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.