Can it be done? A curve from a script or blueprint editor utility?..
I am attempting to create color curves (and then a color atlas) via python scripting. I can’t figure how how to add a key value (or understand if this is even possible or not).
Below is my code that fails to add a key. Up to that point things are fine. Please shine your wisdom upon me!
Bonus: How do find what are available get/set properties?.. I tried dir(asset). For example I know a
asset.get_editor_property(‘adjust_hue’) and asset.set_editor_property(‘adjust_hue’, 0.5) but I don’t know how I should know that apart from having guessed (i.e., open the editor and I see those…)
def create_color_curve(asset_name, asset_path, color_data):
"""
Creates or updates a Color Curve (CurveLinearColor).
Parameters:
- asset_name (str): Name of the Color Curve asset.
- asset_path (str): Path to store the Color Curve.
- color_data (list of unreal.LinearColor): List of colors to add as curve keys.
Returns:
- None
"""
full_asset_path = f"{asset_path}/{asset_name}"
# Check if an asset already exists at the specified path
if unreal.EditorAssetLibrary.does_asset_exist(full_asset_path):
# Delete the existing asset to prevent overwrite prompt
unreal.EditorAssetLibrary.delete_asset(full_asset_path)
unreal.log(f"Existing asset deleted at {full_asset_path}")
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
factory = unreal.CurveLinearColorFactory()
asset = asset_tools.create_asset(asset_name, asset_path, unreal.CurveLinearColor, factory)
time_step = 1.0 / (len(color_data) - 1) if len(color_data) > 1 else 1.0
for i, color in enumerate(color_data):
time = i * time_step
asset.get_editor_property("float_curve").add_key(time, color) # Fails here. Alternative I could create a csv/json and load that instead... if that is better...
# Save the asset to make the changes permanent in the editor's content library.
unreal.EditorAssetLibrary.save_asset(asset.get_path_name())
unreal.log(f"Created asset: {asset_name} at {asset.get_path_name()} with custom properties.")