I keep getting a breakpoint from Nonexistent function x in base z

Godot Version

4.3 Stable, Steam vers.

Question

I’m having trouble figuring out why it’s telling me “Invalid call. Nonexistent function ‘get’ in base ‘Nil’.”

Blockquote
I’ve tried this a few different ways with no success; I’m sorry to be a bother with the forum question, but I don’t know where to look In my code other than the breakpoint line that comes up when I attempt to testrun the program.
I had it half-working at one point but it’s just devolved into showing me a grey background on teh debug window and immediately going to the breakpoint.

Blockquote
extends CharacterBody2D

const WALK_ACCELL = 150
const RUN_ACCELL = 250
const ROLLTO = 270
const WALK_MAX_SPEED = 200
const RUN_MAX_SPEED = 300
const FRICTION = 100
#include in animation “Slide” on frame animation:
#IF user hits left/right and new direction /= old direction, input slide anim
# of “skid” to opposite direction(sliding right after swapping left makes
#Steve use Skid-Right anim.

#var velocity = Vector2.ZERO
#const SPEED = 300.0
#const JUMP_VELOCITY = -400.0

@onready var animationPlayer = $AnimationPlayer
@onready var animationTree = %AnimationTree
var animationState = animationTree.get(“parameters/playback”).travel(“Idles 2”)

#func _physics_process(delta: float) → void:
func _physics_process(delta: float) → void:
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength(“ui_right”) - Input.get_action_strength(“ui_left”)
input_vector.y = Input.get_action_strength(“ui_down”) - Input.get_action_strength(“ui_up”)
input_vector = input_vector.normalized()

if input_vector != Vector2.ZERO:
	
	#if KEY_SHIFT = bool(on/off): 
	#use a
	animationState.travel("Walks")
	#animationTree.set("parameters/Runs/blend_position", input_vector,)
	animationTree.set("parameters/Walks/blend_position", input_vector,)
	#animationTree.set("parameters/Rolls/blend_position", input_vector,)
	animationTree.set("parameters/Idles 2/blend_position", input_vector)
	#velocity += input_vector * WALK * delta
	velocity = velocity.move_toward(input_vector * WALK_ACCELL, WALK_MAX_SPEED * delta)
	#add in input_vector + RUN for Steve_run anims for above
		#specifically seperating run and walk anims so that player can choose
		#to "sneak" in specific areas. Remember, comment for reason, not just explanation.
	#velocity = velocity.limit_length(MAX_SPEED)
	#print(velocity)
	print(input_vector.y)

else:
	velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
	animationTree.travel("parameters/Idles 2/blend_position")
	
	#I think I have to set up a cached command that puts in the last value that was preseed
	#"On release of arrow direction, last x/y input put to Idle direction
	

move_and_slide()

Should that be a $ instead of a %? Might just be a syntax error.

1 Like

Still does it when I do that; except it says…

Blockquote
Invalid call. Nonexistent function ‘get’ in base ‘Nil’.

I can’t say it is a solution, but… I think from what I read it’s the Godot Tree & Scene hierarchy- The script is in the main tree of the player’'s node, and it’s trying to access the Animation Tree in a lower spot on the tree, which is its own scene.
I read on the documentation that you have to get and set a node, just not sure if I implement it, it’ll work or not. Anyone else got ideas?

Try putting
var animationState = animationTree.get(“parameters/playback”).travel(“Idles 2”)
inside a func _ready(): function

like this

var animationState

func _ready():
    animationState = animationTree.get(“parameters/playback”).travel(“Idles 2”)
1 Like

Can you post your scene tree? Unique names aren’t for finding genuinely unique nodes, more for shortening paths, you cannot get a unique named node from a different scene.

1 Like

so @shetburd_0 , I get this error:

Line 22:Invalid character ““” (U+201C).
Line 22:Invalid character “”” (U+201D).
Line 22:Invalid character ““” (U+201C).
Line 22:Expected closing “)” after call arguments.
Line 22:Expected end of statement after variable declaration, found “Literal” instead.
Line 22:Invalid character “”” (U+201D).

@gertkeno :
That’s what I was reading in documentation was the unique nodes bit; I tried to add the unique name modifier as that might fix it but even without it active it has issues.

You must have copied something from a website. the unicode characters that quote “something” are slightly tilted where as in code they expect the ASCII quotes "something"

I’m guessing from the forum, seems like this post copied your original unformatted post, making it into unicode characters

You can’t store .travel("Idles 2") as it returns void

2 Likes

Your original error has to do with these lines. You get the AnimationTree “onready”, but try to use it setting animationState before anything is “onready” since it doesn’t have the annotation. That’s why this is good advice

However you are trying to travel to “Idles 2” which returns void making this assignment fail. You would need to split this into two lines

@onready var animationTree = %AnimationTree
var animationState: AnimationNodeStateMachinePlayback

func _ready() -> void:
    animationState = animationTree.get("parameters/playback")
    animationState.travel("Idles 2")
1 Like

I started following Heartbeast’s RPG in godot old code and tried to implement it into godot 4.3, and read the comments on how one could fix it- I got up to the Statemachine video and that’s where I started having the issues.

I handtyped it this time, and got the new error:
Parser Error: Identifier “AnimationState” not declared in the current scope.

it’s breaking at here:


sorry for the bad commenting; half of it is me reminding myself of where I’m going, and the other half is just trying to make parts of the code work so I can get the /rest/ of it working later.

Capitalization matters, is it supposed to be animationState?

2 Likes

well… That fixed it breaking on that part, but… I’m now back to the square one of this whole debacle:

“Attempt to call function ‘get’ in base ‘null instance’ on a null instance.”
It’s reworded from the main topic of this post, but I’ve seen this error 3 different ways as I’ve been trying to bypass it. Help. ’

What does your animationTree definition look like? let’s try stuffing more things into _ready(), I never much liked @onready anyways.

Is there any change this has been attached to the wrong node? Try also printing the path.

var animationTree: AnimationTree
var animationState: AnimationNodeStateMachinePlayback

func _ready() -> void:
    print(get_path())
    animationTree = %AnimationTree
    animationState = animationTree.get("parameters/playback")
    animationState.travel("Idles 2")
1 Like

I got a bit busy, but… Do you mean when I click the animation player, and then the Animation tree? This is what that function looks like:


also i did what you asked, and got this as a result after I declared animatioTree as a variable:

The print(get_path()) will output something potentially useful in the “Output” section of your debugger.

Looks like you also set animationTree to a type, without the dollar sign this does something weird that you probably don’t want. For now I would recommend removing @onready, and only typing the variable, not setting

# assigning to a type
@onready var animationTree = AnimationTree

# specifying what type the var should expect
var animationTree: AnimationTree
1 Like


This is what I have in the output section… I’m guessing this tells us the basics of what is moving who and where?

And I did edit the var so it’s using a colon rather than equals… my bad. <->’ But that didn’t change much in error messages:

Have I genuinely goofed my code up this bad? ^.^‘’

It tells if your script was attached to another node by accident, which it doesn’t seem to be the case.

print_tree() would tell us all the children in the player scene, but I’m pretty sure it has the AnimationTree child. Have you tried not using a unique name? The animation tree is a direct child anyways.

var animationTree: AnimationTree
var animationState: AnimationNodeStateMachinePlayback

func _ready() -> void:
    print_tree()
    animationTree = $AnimationTree
    animationState = animationTree.get("parameters/playback")
    animationState.travel("Idles 2")
1 Like

I have tried, but not in the way we’re doing the code now. Hold on a tick.

And back to square one. "Cannot call method ‘travel’ on a null value.
Also I moved var animationPlayer = $AnimationPlayer on line 23 because when I stoppedhaving it as an Onready function(I think it’s a function, not sure) the engine got irritable with me and said :The default value is using "$" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this. (Warning treated as error.) Intterestingly enough it says its not used somehow but I think it means its not used in the rest of the func _ready() -> void: codeblock.

This is the output. Is the hierarchy wrong?

This is progress, to some degree. Now it’s an error relating to the AnimationTree’s components, it seems to be missing a AnimationNodeStateMachine as it’s root, but you’ve shown in a screenshot above that it does have state machine, and the “Parameters → Playback” exists in the Inspector. This is very odd, could you paste your entire player script? Make sure to format the paste.

The warning is correct, when you declare var animationPlayer within a function it’s a local declaration and is destroyed when the funciton has ended, since you do not use it in _ready it is never used and could be deleted. With an AnimationTree it’s pretty rare to use the base AnimationPlayer anyways.

1 Like

Yeah I can do that hold on

extends CharacterBody2D

const WALK_ACCELL = 150
const RUN_ACCELL = 250
const ROLLTO = 270
const WALK_MAX_SPEED = 200
const RUN_MAX_SPEED = 300
const FRICTION = 100
#include in animation "Slide" on frame animation:
	#IF user hits left/right and new direction /= old direction, input slide anim
	# of "skid" to opposite direction(sliding right after swapping left makes
	#Steve use Skid-Right anim. 

#var velocity = Vector2.ZERO
#const SPEED = 300.0
#const JUMP_VELOCITY = -400.0
#@onready var animationTree = %AnimationTree
var animationTree: AnimationTree
var animationState: AnimationNodeStateMachinePlayback

func _ready() -> void:
	var animationPlayer = $AnimationPlayer
	#Tried, didn't give infoprint(get_path())
	print_tree()
	animationTree = $AnimationTree
	animationState = animationTree.get("parameters/playback")
	animationState.travel("Idles 2")

#func _physics_process(delta: float) -> void:
func _physics_process(delta: float) -> void:
	var Input_vector = Vector2.ZERO
	Input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
	Input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
	Input_vector = Input_vector.normalized()
	
	if Input_vector != Vector2.ZERO:
		
		#if KEY_SHIFT = bool(on/off): 
		#use a
		animationState.travel("Walks")
		#animationTree.set("parameters/Runs/blend_position", input_vector,)
		animationTree.set("parameters/Walks/blend_position", Input_vector,)
		#animationTree.set("parameters/Rolls/blend_position", input_vector,)
		animationTree.set("parameters/Idles 2/blend_position", Input_vector)
		#velocity += input_vector * WALK * delta
		velocity = velocity.move_toward(Input_vector * WALK_ACCELL, WALK_MAX_SPEED * delta)
		#add in input_vector + RUN for Steve_run anims for above
			#specifically seperating run and walk anims so that player can choose
			#to "sneak" in specific areas. Remember, comment for reason, not just explanation.
		#velocity = velocity.limit_length(MAX_SPEED)
		#print(velocity)
		print(Input_vector.y)
	
	else:
		velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
		animationTree.travel("parameters/Idles 2/blend_position")
		
		#I think I have to set up a cached command that puts in the last value that was preseed
		#"On release of arrow direction, last x/y input put to Idle direction
		
	
	move_and_slide()

I’ve specifically formmatted it so that the grave key ticks are above and below the code- they should avoid anything in the code itself. Sorry for the extraneous comments /in/ the code, but I’m not great with my own reminders.