Search code examples
animationgodotgdscript

Setting one animation key also sets another


I have a custom property and when I add it's animation key I also want other animation keys to be added automatically

e.g. if I press Cusotm Btn animation key, it should automatically press the Position & Rotation Degrees key as well

enter image description here

Is anything like this possible?
(Ideally without having to tamper with AnimationPlayer or Animation nodes?)


Solution

  • had no other choice but to make a custom animation player

    tool
    extends Animation
    class_name CustomAnimation
    
    
    func track_insert_key(track_idx : int, time : float, key, transition : float = 1) -> void:
        .track_insert_key(track_idx, time, key, transition)
        
        var local_node=self.get_local_scene()
        var track_path=track_get_path(track_idx)
        
        var key_node=local_node.get_node(track_path)
        if(key_node.get_class()=="custom_node"):
            var property=track_path.get_subname(0)
            if(property=="custom_prop"):
                remove_track(track_idx)
                var position_track_path=String(track_path).split(":")[0]+":position"
                var position_track_idx=find_track(NodePath(position_track_path))
        
                if(position_track_idx==-1):# if position track does not exist
                    position_track_idx=add_track(0)
                    track_set_path(position_track_idx,position_track_path)
    
                track_insert_key(position_track_idx,time,key_node.position)
                
                #do the same for rotation_degrees
                ...