@fire7side said:
I don't know why you would have to do that in the scene editor but not in code. At some point you aren't going to be wanting to spawn enemies by placing them that way in the scene editor, but you got it working anyway.
edit: I just dragged a couple animated character scenes into my scene main and they both work fine, independently aim at my character, animate, and both shoot at me, same as in code. I suspect it has something to do with your duplication method or the way you made your scene. I know when you import, you have to choose new inherited and make a separate scene. It's not a big deal right now, anyway.
I would really like to get to the bottom of this problem I'm having. I'm experimenting with spawning scenes into the level dynamically through code and I'm having the same issue with animations only working for the first scene instance that gets spawned. I would like to know what I'm doing(or not doing) that's making the scenes share the same animation resource.
Here's how I'm spawning the scenes. Pay no attention to tabs everythings formatted correctly:
scene file is preloaded by a separate script:
var resource: Dictionary = {
"zombieScene": preload("res://scenes/dynamic/zombieb/zombieb.tscn")
}
Scene instance is instantiated in another script:
var objInst = resource["zombieScene"].instance()
Another scene is instantiated using the same script:
var objInst = resource["zombieScene"].instance()
This is the how I'm instancing the scenes. There's not much more to it.
For playing the animation, there's an exported var called AnimPlayer. It's a node path.
export(NodePath) var AnimPlayer
When editing the zombie scene, I click this field in the editor and from the node selection menu, I then click the animation player to give it the correct node path to use. A separate variable(animPlayer) is used to reference the Animationplayer node. This code is used to reference the animation player node:
if AnimPlayer:
animPlayer = get_node(AnimPlayer)
Here's how the zombie scene is composed if this helps:
-zombie(kinematic body scene root)
-StateMachine
-CollisionShape
-mesh
-Skeleton
-AnimationPlayer
Here is the function being used for playing the zombies' animation. I added a debug message:
func playAnimation(name: String, custom_blend: float = -1, custom_speed: float = 1.0, from_end: bool = false):
print("playing animation player node: %s for %s"%[animPlayer.get_instance_id(), name])
animPlayer.play(name, custom_blend, custom_speed, from_end)
In the console, I see two print statements:
playing animation player node: 5071 for Walking
playing animation player node: 5071 for Walking
The two print statements indicate that the "Walking" animation is being called twice but each time for the same AnimationPlayer instance. You can tell by the identical animation player instance Id even though two scenes are being spawned.
I have also loaded the zombie scene and each animation file in the resource editor and checked "Local to scene". And this problem persists. Keep in mind this is for a 3d game with 3d meshes and animations.
I feel like I have been fighting against Godot's tendency to share animation resources for the last two days now and it's getting very tiresome. Any help or feedback would be great.