+1 vote

This follow statement causes dbg error as shown in the figure:

get_node("Parts").add_child(p)

enter image description here

I can not understand the reason for the failure , which still does not interrupt the normal execution of the project .
Anyone have any suggestions ?
Thanks in advance
-j

in Engine by (1,469 points)

2 Answers

0 votes

I think it's because you're using the function wrong as seen in documentation

void    add_child ( Node node, bool legible_unique_name=false )  

And having looked through your game code

Having the "j" or "p" being the (node).new Doesnt work with that, it would appear that to properly use add_child you would need to do something along the lines of

Example

get_node("Test").add_child(Node2d) 

Or something along those lines, i believe that's the reason why the hookups arent working as well

I dont know an alternative fix other than just setting all the joints manually in the editor for now until you find an alternative method of doing this properly

by (483 points)
0 votes

@The_Duskitty

Thank you for your answer. Indeed there is a mistake in my code because the statement

var j = PinJoint2D.new()

is wrong . The joint already exists because is instantiated by the object "Part".

The statement above should be replaced by:

var j = get_node("parts/part "+str(i)+"/jointPart")

However I can not explain the errors of the debugger because the use of the command

add_child

seems correct .

by (1,469 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 webmaster@godotengine.org with your username.