godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.05k stars 21.18k forks source link

Not possible to create AnimationTree from scratch via gdscript #25056

Closed slapin closed 5 years ago

slapin commented 5 years ago

Sorry to bother you in busy pre-release days, happy New Year!

Well, current AnimationTree is working more or less. But when your animation assets size become huge you try to find some ways around that to still e able to manage assets. A good way to do this is via scripting, as Godot supports import scripts, also some things are useful at run time. But I found no way to create AnimationTree from scripts. Well, one can create AnimationTree node via AniationTree.new() but not root resource and subnodes. Please show me if I'm wrong, but it seems that now it is not possible to manipulate AnimationTree resources from scripts. I think that should be resolved somehow.

groud commented 5 years ago

It is totally possible to create everything via scripting:

func _ready():
    var tree = AnimationTree.new()
    tree.tree_root =  AnimationNodeStateMachine.new()
    add_child(tree)

Please ask on the other community channels beforehand when you are not sure about how to do something.

slapin commented 5 years ago

I hope Godot developers would be professional and not get as low as degenerative trolling.

You can't create any useful AnimationTree which does anything via GDScript.

On Thu, Jan 17, 2019 at 11:52 AM Gilles Roudière notifications@github.com wrote:

Closed #25056 https://github.com/godotengine/godot/issues/25056.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/25056#event-2079576087, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAX0yrJK6FAATi3e_MLYO2Vk1ptTNi1ks5vEDnFgaJpZM4aEjSt .

groud commented 5 years ago

I hope Godot developers would be professional and not get as low as degenerative trolling.

I can insure you this is definitely not trolling. Please understand we have a lot of user opening issues everyday, and a lot of them need to be filtered because they are basic questions about how to use the engine.

Now, regarding your problem, you will a have to be a little bit more precise on "creat[ing] any useful AnimationTree which does anything via GDScript.". Animation is not meant to be made via GDscript, that's why we have an editor. Though, as I just showed you (Note: I edited the script, there was an error there), it is totally possible to "manipulate AnimationTree resources from scripts", which answers your initial question. You can create your own animation tree by manipulating AnimationNode resources and attach them via the several available properties.

Now, if you see any limitation there, please be a little bit more precise on your problem.

slapin commented 5 years ago

Aniumation resources can e created and edited by GDScript just fine, you're wrong here. I have 2 problems - short term and long term

Short term problem: I have 2000 .escn scenes. I need to extract animation resources from scenes (done) via importer script and then Create AnimationStateMachine state with BlendTree inside, which blends each animation resource with another 3 animations. Doing this manually is huge task - I have to load each animation into AnimationPlayer then create state, create Blend tree, create a set of nodes in BlendTree, etc. This is extremely tedious. There is workaround by creating .tres resource using python script, but that is noot a good solution because it is very hacky in my case. I would prefer API which would allow creating AnimationTree from scratch with all supported nodes so that I could create it procedurally without heavy manual labour or external scripts.

slapin commented 5 years ago

The long term problem is setting-up part of animation tree procedurally at run time to allow customization of animation set. I want to create procedural animation resources and add them to the tree. This way I will not need to have random animations pre-generated and will generate them at run time and add to AnimationTree.

groud commented 5 years ago

Aniumation resources can e created and edited by GDScript just fine, you're wrong here.

No I am not.

Everything you describe is already possible, here is an example on how you could automatically generate a state machine, with two animations and two transitions :

    var tree = AnimationTree.new()
    var state_machine = AnimationNodeStateMachine.new()
    tree.tree_root = state_machine

    var anim_node1 = AnimationNodeAnimation.new()
    anim_node1.animation = "anim1"
    var anim_node2 = AnimationNodeAnimation.new()
    anim_node2.animation = "anim1"

    state_machine.add_node("anim1", anim_node1)
    state_machine.add_node("anim2", anim_node2)

    var transition1 = AnimationNodeStateMachineTransition.new()
    var transition2 = AnimationNodeStateMachineTransition.new()

    state_machine.add_transition("anim1", "anim2", transition1)
    state_machine.add_transition("anim2", "anim1", transition2)

You could also add blend tree nodes, but I can ensure you all you describe is already possible.

mrcdk commented 5 years ago

You can create an AnimationTree without any issues using GDScript (or C# I guess, I haven't tried that) only:

    tree = AnimationTree.new()
    add_child(tree)
    tree.anim_player = $AnimationPlayer.get_path()

    var root = AnimationNodeBlendSpace1D.new()
    tree.tree_root = root

    var anim1 = AnimationNodeAnimation.new()
    anim1.animation = "test"
    var anim2 = AnimationNodeAnimation.new()
    anim2.animation = "test2"

    root.add_blend_point(anim1, 0)
    root.add_blend_point(anim2, 1)

    tree.active = true

That creates an animation tree with a BlendSpace1D as its root and adds 2 animations to the BlendSpace1D then you can use tree["parameters/blend_position"] to modify that value like you would do normally

EDIT: ops 😅 looks like the issue didn't update with new posts before I posted this

slapin commented 5 years ago

Thanks a lot for your help! You really increased my quality of life.

Could we please have the examples added to the AnimationTree doc on site? What needs to be done for this to happen? https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html

It is not only me who have problems like that. Thanks a lot to you people! Have a nice day!

On Thu, Jan 17, 2019 at 12:46 PM Gilles Roudière notifications@github.com wrote:

Aniumation resources can e created and edited by GDScript just fine, you're wrong here.

No I am not.

Everything you describe is already possible, here is an example on how you could automatically generate a state machine, with two animations and two transitions :

var tree = AnimationTree.new() var state_machine = AnimationNodeStateMachine.new() tree.tree_root = state_machine

var anim_node1 = AnimationNodeAnimation.new() anim_node1.animation = "anim1" var anim_node2 = AnimationNodeAnimation.new() anim_node2.animation = "anim1"

state_machine.add_node("anim1", anim_node1) state_machine.add_node("anim2", anim_node2)

var transition1 = AnimationNodeStateMachineTransition.new() var transition2 = AnimationNodeStateMachineTransition.new()

state_machine.add_transition("anim1", "anim2", transition1) state_machine.add_transition("anim2", "anim1", transition2)

You could also add blend tree nodes, but I can ensure you all you describe is already possible.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/25056#issuecomment-455108336, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAX0wfumIqgXDxKaoBl1ZefNMJvslN0ks5vEEaMgaJpZM4aEjSt .

groud commented 5 years ago

Could we please have the examples added to the AnimationTree doc on site? What needs to be done for this to happen? https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html

You can open an issue on the Godot docs repository, though I am not sure this belongs to the official documentation. That being said, maybe a tutorial would be appropriate.

Have a nice day!

So do you ;)