Error seeking weapon node for animation

Godot Version 4.2.2

Question

Hi everyone! In my hotline miami like game I have two weapon scenes: katana and knife. In player scene I have one AnimationPlayer with two animations in it: “katana_attack” and “knife_attack”. Also player has the node “Weapon” with weapon scene (katana or knife) in hands. Player may have only one weapon in Weapon node.
The problem happens when the player has knife. Terminal starts blasting with errors that katana animation can’t reach katana scene position, rotation, etc. Similar thing happens with katana in player hands but now terminal throws errors about knife position? rotation, etc.

How can I fix this problem? I call attack animation dinamically according to weapon in hands but still missing weapon causes trouble.

Thank you!

Make a “Weapon” node parent for either the katana or knife, then animate that Weapon node instead; it will always exist.

1 Like

Hi! Brilliant idea!!! Thank you very much)
But unfortunately here comes another problem)) In my AnimationPlayer I change katana’s position, rotation and collision layers (so the Player can hit Enemy only when the animation is going and not just by touching Enemy with katana without animation)
So if I animate parent Weapon 2dnode instead of area2d(katana or knife) I could not access theur collision layers(((
I know my collision layers sollution sounds a little sloppy. Do you know the better way?

Sorry for not mentioning it in the first place(

What if u go like this

Weapon node2d # script for collision/hitscan

Katana Sprite
Collision object/area2d
Knife sprite
Collision object/area2d

(Remember to give them shapes)

And in script u just make that both are always there, but uppon weapon change make a function:

func on_weapon_change(): # signal

#you will need to make scripts yourself here

If current_weapon_is(Knife):

#make it show its sprite, animation and collision
show_katana()
else
show_knife()

I’m newbie so watch out for my logic but i hope i gave you a good logic idea.

Additionally show func can hide the other right away as first line of code

1 Like

thank you for your help! But I don’t know how to make my animation show via script… It would be great to load for example knife_attack script when Player have knife in hands but I couldn’t find working solution for this(((

Extra image:
image

Animation example
image

Maybe set the AnimationPlayer’s root to the weapon, but you would have to update the root when the weapon changes. The animation track paths would look like .:position, .:rotation which does not require any specific naming, only that the properties exist.

On the other hand you could name the weapons the same thing, instead of Katana/Knife rename them when added to “Weapon”. Then the animation tracks would work without error as Weapon:position should always exist.

1 Like

Guys, thank you very much for all your help and thoughts! I came up with a solution)
I just made animation player empty and add specific animation library with weapon specific animation via Player script. It was so simple, sorry for such a noobie question((
Thanks again!!!

1 Like