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.

godotengine.org | Twitter

0 votes

Hello,

I have been running into an error, which I don't understand. It crashes my game and it looks like it happens when I try to set the position of an object that is not there. However, before setting the position, I check if the object is there.

func _process(delta):
if carried_object:
    carried_object.position = position + $Body.position + Body/CarryPosition.position

The error occurs when I try to set the position of carried_object, and the debugger marks the variable as unoccupied. However, shouldn't the line, if carried_object: prevent this from happening? I assign carried_object a value in _physics_process.

I hope you can help me. Thanks :-)

in Engine by (24 points)

1 Answer

+1 vote

I had this problem as well. I assume carried_object is an onready var?
ie:

onready var Life = get_node("/root/Main/GUI/Game/Score")

You have to call the node in functions. Otherwise restarting the code explodes in ball of flames. Idk why. I ended up doing this.

extends CanvasLayer

onready var Score
onready var Life

Then in my function

func updatescore():
    Score = get_node("/root/Main/GUI/Game/Score")
    Score.text = str(global.score)

Idk if there is an easier way to do it? But thats how i fixed the issue

by (51 points)

Thanks for your help. However, I have not been able to transfer this concept to my code. carried_object is a node which is spawned in the game. When I tried to re-define the node its movement started lagging... But thanks anyway :-)

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.