SpriteAnimation2d not animating if apart of instanciated code

v4.1.1 stable

Question

i have 3 trees that look something like this:
image

image

image

the first scene instantiates and adds the level loader using code (that works perfectly). the level loader has my player character, Blibo, and the player character has an animatedsprite2d node, with all the animations worked out.

the code looks like this:


func spriteAnimation():
	var input_dir: Vector2 = input()
	if(spriteIsLoaded):
		if(is_on_wall() and not is_on_floor()):
			desiredAnimation = "Wall Slide"
		elif(not is_on_floor() and not is_on_wall() and velocity.y < 0):
			desiredAnimation = "Jump Up"
		elif(not is_on_floor() and not is_on_wall() and velocity.y > 0) :
			desiredAnimation = "Jump Down"
		elif(input_dir.x != 0):
			desiredAnimation = "Walk"
		elif(is_on_floor()):
			desiredAnimation = "Idle"
		if(BliboSprite.animation != desiredAnimation):
			BliboSprite.play(desiredAnimation)

func _on_main_body_tree_entered():
	spriteIsLoaded = true
	pass # Replace with function body.

and yes, i do call on spriteAnimation() in the _physics_process function.

here comes the problem. the animations i added only display the 1st frame, no matter what i do.

the thing is, i have gotten them to animate before! before using the structure im currently using, i had all the objects in one big tree like this:

game
-test_level
–blibo
—animatedsprite2d

and then it worked perfectly. having the character instantiated seems to have broken my animations! wah!!!

here is the code that instantiates the scenes btw:

func _process(delta):
	changeGameState(buttons)
	readGameState(gameState)
	pass

func readGameState(state):
	match state:
		"MainMenu":
			var children = self.get_children()
			var isChild = false
			for child in children:
				if(child.name == "Main Menu"):
					isChild = true
			if(!isChild):
				self.add_child(mainMenuInst)
		"Levels":
			var children = self.get_children()
			var isChild = false
			for child in children:
				if(child.name == "Level Loader"):
					isChild = true
			if(!isChild):
				self.add_child(levelLoaderInst)
				levelLoaderInst.get_child(0).get_child(0).play()
		"Exit":
			get_tree().quit()


func changeGameState(aButtons):
	if aButtons.Play.playPressed:
		gameState = "Levels"
		for child in self.get_children():
			self.remove_child(child)
	elif aButtons.Settings.settingPressed:
		gameState = "Settings"
	elif aButtons.Credits.creditsPressed:
		gameState = "Credits"
	elif aButtons.Exit.exitPressed:
		gameState = "Exit"

sorry that this is a long read. but how can i fix this? :frowning:

Are you getting any error in debugger ?

1 Like

nope. not a single error. as clean as can be