Python and Editor Scripting
Every editor tool of AFT is a Blueprint callable function of UAFTEditorLibrary (category AFT | Editor). They can be used from
Python (unreal.AFTEditorLibrary, snake_case names) and from Editor Utility Widgets / Blueprints.
Enable the Python Editor Script Plugin of the engine to use Python (enabled in the template).
Functions
| Function | Result |
|---|---|
CreateFighterFromAnimations(FighterName, PackagePath, Mesh, AnimationFolder, ThemeColor) | Fighter data asset + common actions + commands + 2 palettes, like the Fighter Wizard window (Tools > AFT > Fighter Wizard). Refuses an empty or invalid name (letters, digits, _) or a folder outside the content. See Create a Fighter from Animations. |
PreviewAnimationMatches(Mesh, AnimationFolder) | The matching list of the wizard: for each standard action, the animation it would get (Matched, Fallback or None), the names searched and whether the animation is of another skeleton. Creates nothing. |
GenerateCommonActions(Fighter, AnimationFolder) | Creates the standard actions whose slot is empty and wires the slots, commands and gatlings. Returns the number of actions created. |
GenerateMissingActions(Fighter, AnimationFolder) | Creates only the standard actions the fighter does not have yet, without touching the existing ones (after a template update, such as the run or the dash attacks); the existing normals only gain the gatlings into the new normals. Returns the number of actions created. |
RegenerateActions(Fighter, AnimationFolder, ActionNames) | Rebuilds these standard actions from the template, by name (timeline and hits replaced, commands kept); the other ones as GenerateMissingActions. Returns the number of actions created or rebuilt. |
SetActionHitboxes(Action, X, Y, Width, Height) | Moves every hitbox of an action to this box (center X forward / Y up from the feet, size, in cm), keeping timing, hits and cancels. Returns the number of hitboxes changed. |
CreateActionForFighter(Fighter, Name, Category, Animation) | One action in <fighter folder>/Actions, added to the fighter. The animation becomes one Animation event over the whole action, on its Animation track. |
CreateDefaultStateGraph(PackagePath, Name) | The standard movement state graph. |
ResetStateGraphToDefault(Graph) | Replaces a state graph by the standard graph and arranges it, like the Reset To Default button. |
ArrangeStateGraph(Graph) | Readable layout of a state graph (aliases for shared transitions, shortcuts instead of long arrows), like the Auto Arrange button. The behavior does not change. |
CreateDefaultGameContent(PackagePath, ProjectPackagePath) | Default rules, tag team rules, state graph and the five game modes in PackagePath, and the default cue set in ProjectPackagePath (CreateDefaultCueSet). No arcade ladder: each fighter has its own (CreateArcadeLadder). |
CreateArcadeLadder(Fighter, PackagePath) | The arcade ladder of a fighter: DA_<FighterId>_Arcade in PackagePath (empty = the fighter folder), filled with its default fights (one per other fighter of the roster, CPU level 3 rising to 7, random stage, 3 continues) and set as its ArcadeLadder. A fighter that already has a ladder keeps it (returned as is). Not saved (SaveAllUnder). |
CreateDefaultCueSet(PackagePath) | DA_AFT_DefaultCues: the project hit / guard sparks and sounds, and the camera shakes and vibrations of the template. Fills only what an entry leaves empty. Returns the set. |
CreateFighterSequence(Fighter, bVictory, DurationFrames) | Intro / victory Level Sequence. See Cinematics. |
CreateActionSequence(Action, StartFrame) | Level Sequence of a cinematic super: LS_<Action> in <fighter folder>/Cinematics (60 fps, Fighter / Opponent bindings, a camera close on the fighter) and a Cinematic event on the action, from StartFrame to the end of the action (Cinematics track). Returns the sequence. |
SaveAllUnder(PackagePath) | Saves the dirty packages of a folder. |
Examples
Create a fighter and its cinematics:
import unreal
aft = unreal.AFTEditorLibrary
mesh = unreal.EditorAssetLibrary.load_asset("/Game/Hero/Mesh/SK_Hero")
fighter = aft.create_fighter_from_animations("Hero", "/Game/Fighters/Hero", mesh, "/Game/Hero/Animations",
unreal.LinearColor(1.0, 0.3, 0.2, 1.0))
aft.create_fighter_sequence(fighter, False, 180) # intro, 3 seconds
aft.create_fighter_sequence(fighter, True, 180) # victory
aft.save_all_under("/Game/Fighters/Hero")
Add an action to an existing fighter:
fighter = unreal.EditorAssetLibrary.load_asset("/Game/Fighters/Hero/DA_Hero")
anim = unreal.EditorAssetLibrary.load_asset("/Game/Hero/Animations/A_Hero_Uppercut")
action = aft.create_action_for_fighter(fighter, "Special_Uppercut", unreal.AFTActionCategory.SPECIAL, anim)
Bring a fighter made with an older template up to date (for example to get the run, the six button normals and the dash attacks), keeping its existing actions, then rebuild its throw as the new held throw:
fighter = unreal.EditorAssetLibrary.load_asset("/Game/Fighters/Hero/DA_Hero")
created = aft.generate_missing_actions(fighter, "/Game/Hero/Animations")
print(created, "new actions") # DA_Hero_Run, DA_Hero_Normal_5D, DA_Hero_DashAttack_A...
aft.regenerate_actions(fighter, "/Game/Hero/Animations", ["Throw_Attempt", "Throw_Success"])
aft.save_all_under("/Game/Fighters/Hero")
Fit the hitbox of a normal on another animation (center 70 cm forward, 120 cm up, 40 x 30 cm):
action = unreal.EditorAssetLibrary.load_asset("/Game/Fighters/Hero/Actions/DA_Hero_Normal_5A")
aft.set_action_hitboxes(action, 70.0, 120.0, 40.0, 30.0)
Edit data like any Unreal asset with get_editor_property / set_editor_property (Python names are snake_case:
total_frames, overlay_material, palettes...).
Timeline scripting
The timeline of an action can be written from a script, without the Fighter Editor: these
functions (category AFT | Editor | Timeline) add the frame events on the
usual tracks. Frames are action frames (0 = the first frame), distances are in cm (X forward from the fighter, Y up from the
feet), velocities in cm per frame. Tags are given by name ("AFT.Cue.Hit.Heavy", "None" for no tag) and must exist in the
project tag list: an unknown tag is logged as a warning. Every call marks the action dirty: save with SaveAllUnder.
| Function | Event (track) |
|---|---|
RemoveActionEvents(Action, EventType, Track) | Removes the events of a type (None = every type, for example unreal.AFTFrameEvent_Hitbox.static_struct()) from a track (None = every track). Returns the number of events removed. |
AddHitboxEvent(Action, Start, Duration, X, Y, Width, Height, HitIndex = 0) | Hitbox using the hit definition HitIndex (Hitboxes). |
AddHurtboxEvent(Action, Start, Duration, X, Y, Width, Height) | Hurtbox override (Hurtboxes). |
AddCueEvent(Action, Frame, Cue, OffsetX = 0, OffsetY = 0, bAttached = true) | Cue (VFX / sound / effect actor of the cue set) at an offset from the fighter (Cues). |
AddSuperFreezeEvent(Action, Frame, FreezeFrames, Cue = None) | Super flash: freezes everything but the fighter. None = AFT.Cue.SuperFreeze (Cues). |
AddVelocityEvent(Action, Start, Duration, X, bAffectY = false, Y = 0, bEveryFrame = false) | Sets the velocity, on every frame of the event with bEveryFrame (Movement). |
AddGravityEvent(Action, Start, Duration, GravityPercent = 0) | Gravity scale, 0 = float (Movement). |
AddInvulnerableEvent(Action, Start, Duration, bStrike = true, bThrow = true, bProjectile = true) | Invulnerability (Hurtboxes). |
AddStateFlagsEvent(Action, Start, Duration, Flags) | State flags, EAFTStateFlag bitmask: CounterHitState = 4, NoAutoTurn = 8, IgnoreScreenLimit = 64... (Cancels). |
AddCancelWindowEvent(Action, Start, Duration, Condition, Categories, Actions) | Cancel window: EAFTContactCondition, EAFTCancelFlags bitmask (Normal = 1, CommandNormal = 2, Special = 4, Super = 8, Jump = 16, Dash = 32, Movement = 64, Throw = 128) and explicit target actions (gatlings) (Cancels). |
AddHoldOpponentEvent(Action, Start, Duration, X, Y, EndX, EndY) | Holds the opponent at (X, Y), moving to (EndX, EndY) over the event when they differ: held throws, cinematic supers (Throw). |
AddReleaseOpponentEvent(Action, Frame, HitIndex, VelocityX, VelocityY) | Throws the held opponent with the hit definition HitIndex (damage) and a launch velocity (Throw). |
AddProjectileEvent(Action, Frame, ProjectileAction, OffsetX, OffsetY, VelocityX, VelocityY, LifetimeFrames = 120) | Spawns a projectile driven by its own action (Cues). |
AddMeterEvent(Action, Frame, Amount) | Gains (positive) or spends (negative) meter (Cues). |
AddCinematicEvent(Action, Start, Duration, Sequence, bHideHUD = true) | Plays a Level Sequence over the event frames: cinematic supers (Cinematics). |
SetHitCues(Action, HitIndex, HitCue, BlockCue) | Sets the hit / block cues of a hit definition (None = the default spark). Returns false when the hit does not exist. |
SetCueDefinition(CueSet, Cue, Definition) | Adds or replaces the entry of a cue tag in a cue set (unreal.AFTCueDefinition: effect, sound, effect actor, camera impulse, rumble...). |
CreateActionSequence(Action, StartFrame) | Level Sequence and Cinematic event of a cinematic super (see Functions). |
The hit definitions are edited as properties: build unreal.AFTHitDefinition values and set the hits of the action. Rebuild
an attack from a script (the events of the script are removed first, so the script can run again):
import unreal
aft = unreal.AFTEditorLibrary
action = unreal.EditorAssetLibrary.load_asset("/Game/Fighters/Hero/Actions/DA_Hero_Normal_5C")
for event_type in (unreal.AFTFrameEvent_Hitbox, unreal.AFTFrameEvent_Cue, unreal.AFTFrameEvent_CancelWindow):
aft.remove_action_events(action, event_type.static_struct(), "None")
hit = unreal.AFTHitDefinition()
hit.set_editor_property("hit_name", "5C")
hit.set_editor_property("attack_level", 3)
hit.set_editor_property("damage", 520)
action.set_editor_property("hits", [hit])
aft.add_cue_event(action, 8, "AFT.Cue.Swing", 40.0, 120.0, True) # whiff sound
aft.add_hitbox_event(action, 9, 3, 85.0, 115.0, 70.0, 40.0, 0)
aft.set_hit_cues(action, 0, "AFT.Cue.Hit.Default", "None")
aft.add_cancel_window_event(action, 9, 12, unreal.AFTContactCondition.ON_CONTACT,
4 | 8, []) # specials and supers, on hit or block
cues = unreal.EditorAssetLibrary.load_asset("/Game/Fighters/Hero/DA_Hero_Cues")
slash = unreal.EditorAssetLibrary.load_blueprint_class("/Game/Fighters/Hero/VFX/BP_Hero_FX_Slash_Heavy")
entry = unreal.AFTCueDefinition()
entry.set_editor_property("effect_actor", slash)
entry.set_editor_property("camera_impulse", 0.4)
aft.set_cue_definition(cues, "AFT.Cue.Hero.Slash.Heavy", entry)
aft.save_all_under("/Game/Fighters/Hero")
A complete cinematic super written from Python is in Cinematic Supers.
Render fighters
The AFT Character Render Studio actor (unreal.AFTCharacterRenderStudio) renders fighters to PNG from scripts too:
apply_fighter, frame_shot, render_to_file(shot, width, height, file_name), render_fighter_images (Icon, Portrait and Full
Art of the fighter) and get_last_coverage. See Character Render Studio for
an example.
CPU profiles
UAFTCpuProfile::GenerateFromFighter(Fighter, Mode) builds the tactics of a CPU profile from a move list,
and UAFTCpuSimulator::Simulate(Settings) plays headless matches of a CPU. Create a CPU profile for each fighter of a folder:
import unreal
aft = unreal.AFTEditorLibrary
assets = unreal.AssetToolsHelpers.get_asset_tools()
common = unreal.EditorAssetLibrary.load_asset("/AFT/Data/DA_AFT_CpuCommon")
fighter = unreal.EditorAssetLibrary.load_asset("/Game/Fighters/Hero/DA_Hero")
profile = assets.create_asset("DA_Hero_Cpu", "/Game/Fighters/Hero", unreal.AFTCpuProfile, unreal.AFTCpuProfileFactory())
profile.set_editor_property("parent", common)
profile.set_editor_property("override_levels", False) # the levels of DA_AFT_CpuCommon
profile.set_editor_property("preview_fighter", fighter)
profile.generate_from_fighter(fighter, unreal.AFTCpuGenerateMode.FIGHTER_ONLY)
fighter.set_editor_property("cpu_profile", profile)
aft.save_all_under("/Game/Fighters/Hero")
See CPU Editor to run simulations from a script.
How the template content was built
The template content was generated with these functions, in this order:
- default rules, state graph and game modes (
/AFT/Data) and the project cue set; - the sample fighter Quinn, from its animations, with the toon palettes and the outline;
- its intro and victory Level Sequences;
- the CPU profiles:
DA_AFT_CpuCommon(Common Only, plugin content) and one per fighter,DA_Quinn_Cpu(Fighter Moves Only, child of the common profile), assigned to the fighter when itsCpuProfileis empty; - the second sample fighter Manny:
DA_Manny, a copy ofDA_Quinn(EditorAssetLibrary.duplicate_asset) that keeps her actions, commands, slots, CPU profile and Level Sequences, with his own Fighter Id, mesh, toon palettes and theme color (his UI images are then rendered with the Character Render Studio); - the training room map (AFT Stage Info + AFT Match Tester with the Training preset) and the front end map;
- the training stage data asset;
- the arcade ladders
DA_Quinn_ArcadeandDA_Manny_Arcade:CreateArcadeLadder, then the fights set from a table in the script (opponent, palette, stage, CPU level, title, match options), only on new ladders.
fighter = unreal.load_asset("/Game/MyGame/Fighters/Ryo/DA_Ryo")
ladder = unreal.AFTEditorLibrary.create_arcade_ladder(fighter, "")
boss = unreal.AFTTeamMemberConfig()
boss.set_editor_property("fighter", unreal.load_asset("/Game/MyGame/Fighters/Boss/DA_Boss"))
final = unreal.AFTArcadeFight()
final.set_editor_property("opponents", [boss])
final.set_editor_property("cpu_level", 8)
final.set_editor_property("title", unreal.Text("FINAL BATTLE"))
options = unreal.AFTMatchOptions()
options.set_editor_property("rounds_to_win", 3)
final.set_editor_property("override_match_options", True)
final.set_editor_property("match_options", options)
ladder.set_editor_property("fights", list(ladder.get_editor_property("fights")) + [final])
unreal.AFTEditorLibrary.save_all_under("/Game/MyGame/Fighters")
Follow the same steps to batch-create your own roster, from a script run with the editor closed:
UnrealEditor-Cmd.exe AnimeFighterTemplate.uproject -run=pythonscript -script="<path>/your_script.py" -unattended