Custom Action scripting – agent is null

NodeCanvas Forums Support Custom Action scripting – agent is null

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #17889
    perfex
    Participant

    Hi all,

    I’ve recently started getting into NodeCanvas, so forgive me if it is a stupid question. However, the documentation on scripting custom Actions seems to be rather thin from what I have found (if these are the right docs https://nodecanvas.paradoxnotion.com/documentation/?section=graphowner-api).
    Anyways, I am trying to create a simple FSM for a character in a 2D platformer. Idle state, running state and all that jazz. However, in my scripts, the agent field seems to be null, and I cannot programatically get any Component in my agent. My FSM is an Asset, as I intend to use it on other characters as well. Heres the custom action script in question:

    ——-
    namespace CharacterStates {

    [Category(“…”)]
    [Description(“..”)]
    public class RunningState : ActionTask<GameObject> {

    private CharacterMovement characterMovement;

    //Use for initialization. This is called only once in the lifetime of the task.
    //Return null if init was successfull. Return an error string otherwise
    protected override string OnInit() {
    return null;
    }

    //This is called once each time the task is enabled.
    //Call EndAction() to mark the action as finished, either in success or failure.
    //EndAction can be called from anywhere.
    protected override void OnExecute() {
    characterMovement = agent.GetComponent<CharacterMovement>();
    //EndAction(true);
    }

    //Called once per frame while the action is active.
    protected override void OnUpdate() {
    agent.transform.position = new Vector3(
    agent.transform.position.x + characterMovement.movementInput * characterMovement.baseMoveSpeed * Time.deltaTime,
    agent.transform.position.y,
    agent.transform.position.z);
    }

    //Called when the task is disabled.
    protected override void OnStop() {

    }

    //Called when the task is paused.
    protected override void OnPause() {

    }
    }
    }
    ——-

    Also, if there are some other sources I can look to in order to find more about custom scripting, I would be very grateful if you sent them my way :D.
    Thanks in advance!

    #17897
    Gavalakis
    Keymaster

    Hello there,

    Please use a ‘Component’ derived type as the generic argument of ActionTask<T>. GameObject type is not supported there, so the ‘Transform’ type is best to be used there for a gameobject (since all gameobjects have a Transform 🙂 ). Alternatively you could also use an interface type for the generic argument (this is why there is no restriction for components only types on the argument).

    Let me know if that works for you.

    Here are a couple more docs for creating Tasks by the way:

    nodecanvas.paradoxnotion.com/documentation/?section=creating-custom-tasks
    nodecanvas.paradoxnotion.com/documentation/?section=using-task-attributes
    nodecanvas.paradoxnotion.com/documentation/?section=using-bbparameters-in-tasks
    nodecanvas.paradoxnotion.com/documentation/?section=creating-generic-tasks

    Cheers!

    Join us on Discord: https://discord.gg/97q2Rjh

    #17911
    perfex
    Participant

    Hey Gavalakis,

    That did work, thanks!
    The links you sent seem to just be pointing towards the first page of the documentation. Could you review the links and send them again? I am curious as to what is on them :D.

    Thanks again!

    #17972
    Gavalakis
    Keymaster

    Hello. Sorry for late reply. I edited my post above to show the link correctly. 🙂

    Join us on Discord: https://discord.gg/97q2Rjh

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.