Hi, I have two character nodes in a turn-based battle with a bunch of stats in them. I would like for them to switch places and then inherit each other's data/animation. Essentially, I want the Player1 node to become the Player2 node and vice versa.
I accomplished this in old projects by doing something like:
var temp = p1.stats
p1.stats = p2.stats
p2.stats = temp
And repeat for every value I need. It could work here, but when accounting for all the variables and animations, it sounds annoying. Plus, anything I add in the future will also need to be added to this switch code. I'm looking to save a future headache.
So I figured I could just swap the .name properties of the nodes. That would work exactly how I want. So I tested this:
var p1 = $Player1
var p2 = $Player2
print(p1.name)
p1.set_name("temp")
p2.set_name("Player1")
p1.set_name("Player2")
print(p1.name)
And it does indeed print "Player1" then "Player2." The name does change. But unfortunately, they've not actually switched in-game. Godot apparently keeps track of name changes after runtime so that any code referring to the original name gets updated accordingly. That sounds like a great QOL feature, but not for me, because that's the whole reason I changed the names in the first place!
So my question is: is there a way to turn this off? Can I just let anything referencing "Player1" instead target a different node if I switch them? Or am I doomed to rewrite anything that references the node directly?