This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello everyone. I recently moved all the code of a weapon inside the player script because I want it to interact with rng and I don't know how to do it otherwise. I have a bow that shoots where the mouse is at, I use a getglobalposition. The thing is, now that I've changed everything, when I try to shoot the project crashes with the error message you read on the title. I think that the issue itself is related to the fact that the code part that makes the weapon face towards the mouse is in the other script, if you know how to fix this, please let me know.

Here's the code from the bow (I just want it to face the mouse):

extends Node2D
func _process(delta: float) -> void:

And here's the part of the player script that shoots the arrows, etc... :

extends Character
 var arrow = preload("res://Arrowfinal.tscn")
 var rubberarrow = preload("res://RuberArrow.tscn")`

if reroll == 1:
    if Input.is_action_just_pressed("ui_attack") and current_weapon == 1 and can_fire:
        var rubberarrow_instance = rubberarrow.instance()
        rubberarrow_instance.position = $Arrowpoint.get_global_position()
        rubberarrow_instance.rotation_degrees = rotation_degrees
        rubberarrow_instance.apply_impulse(Vector2().normalized(), Vector2(arrow_speed, 0).rotated(rotation))
        can_fire = false
        yield(get_tree().create_timer(fire_rate), "timeout")
        can_fire = true
Godot version v3.5.1
in Engine by (35 points)

In the above code, there's only one reference to get_global_position(). There, the problem is that it's being called on the $Arrowpoint node, which (according to the error), is null.

For that code to work, the node containing that script must have a direct child named Arrowpoint. I assume it does not.

You mention that you've refactored the code because you want to interact with an rng. While I don't see any evidence of that above, you should be able to find another way to interact wtih your rng. For example:

  • Create a single RNG in a global singleton and use it everywhere in yoru game
  • Create a local RNG at the point where you want/need it

Hey, thanks for answering. The issue with moving the arrowpoint for it to be a child of the player node is that the point itself will inherit the direction from the player and not from the bow. Is there any way I can fix this?

Also don't worry about the rng, I think I managed to sort it out, I just didn't include it in the post because I think it's irrelevant and I don't want to bother anyone.

I'm not suggesting that your rearrange your scene tree to match the script. I'm only pointing out what the tree would need to look like for that $Arrowpoint node reference to resolve correctly in the posted code.

It's really hard to provide any useful info without understanding how your scene tree is currently organized...

Indeed, it appears that a missing child node named Arrowpoint is probably the source of the error

Please log in or register to answer this question.

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.