Unreal.js icon indicating copy to clipboard operation
Unreal.js copied to clipboard

Issue with Overriding BP Value

Open mix-spice opened this issue 1 year ago • 0 comments

Hey guys, so I have created the Stop() function that works fine and I am trying to change a value of throttleInput that I have in this function. The function is made via BP(see a photo) Screenshot 2024-06-13 185253

The issue lies in my unrel.js code, that just doesnt change that value. I dont know where the issue is, I've tried different ways around and it still doesnt see to work for me. Below I'll paste a code that I wrote, maybe someone could be kind to check it out and help me figure out where the issue lies? Thanks in advance!

"use strict";

const SportAIBlueprint = Blueprint.Load('/Game/VehicleTemplate/Blueprints/SportsCar/Sport_AI').GeneratedClass;

// Define a class extending the loaded Blueprint class Sport_AI extends SportAIBlueprint { properties() { this.VehicleMovementComponent; this.Stand; }

Stop() {
    console.log("Overridden Stop function called");

    // Get the Vehicle Movement Component
    let vehicleMovementComponent = this.VehicleMovementComponent;

    if (vehicleMovementComponent) {
        // Set Throttle Input to the desired value
        vehicleMovementComponent.SetThrottleInput(-1.0);
        
        // Optionally, set Handbrake Input
        vehicleMovementComponent.SetHandbrakeInput(true);

        // Update any other necessary properties
        this.Stand = true;

        console.log("Throttle input set to -40.0 and handbrake applied.");
    } else {
        console.error("VehicleMovementComponent not found.");
    }
}

}

// Compile the Sport_AI class let SportAI_C = require('uclass')()(global,Sport_AI);

function getFirstSportAIInstance() { let instances = GWorld.GetAllActorsOfClass(SportAI_C).OutActors[0]; return instances.length > 0 ? instances[0] : null; }

const Sport_AIActorBP = '/Game/VehicleTemplate/Blueprints/SportsCar/Sport_AI.Sport_AI_C'; let Sport_AIActor = GWorld.GetAllActorsOfClass(Sport_AIActorBP).OutActors; let Sport_AI_instance = Sport_AIActor.length > 0 ? Sport_AIActor[0] : null;

function main() { let car = getFirstSportAIInstance(); if (car && car.Stop) { car.Stop(); } else if (!car) { console.error("No instances of Sport_AI found."); } else { console.error("Stop method not found on instance:", car); } }

main();

mix-spice avatar Jun 13 '24 16:06 mix-spice