Forum rules - please read before posting.

Custom Action ConstantID breaks after a while

edited December 2022 in Technical Q&A

Hi everyone,

I have a custom AC action that changes the animation of an NPC depending on their mood variable.

It uses the ConstantID to find the character object. The issue is, after I set it it works for a while, but then after a while for reasons I can't fathom it suddenly breaks and can't find it anymore and I get these 2 errors:

until I set it manually in the actionlist again.

I've probably missed something in the custom action template because I'm new to c# but does anyone see anything wrong?
Here's the action script: https://pastebin.com/CRLHeXeX

Thank you :)

Edit: It seems to be looking for the character in scene, and throws that error if they haven't spawned before the script is run. Is there a make the code wait for 2 seconds if character is not found? And then return 0f if it still isn't there I guess?

Comments

  • You'll need to add a null-check at the top of your Run function to prevent the missing Animator from causing an error:

    if (Animator == null) return 0f;
    

    Is there a make the code wait for 2 seconds if character is not found?

    It's not the best way to approach it, in case its run when the character hasn't been requested to spawn in.

    How and when are you adding the characters, and when are you running the above Action? The best approach should be to only run the above ActionList itself once the character is present.

  • Hi Chris,
    I believe it's because the characters are spawned in through a walking script (checking if their location variable is set to the current room, if it is then they spawn)

    It uses the send message action

    And there's no wait until finish obviously so it just carries on and reaches my script before it finishes spawning in

  • It'd be best to run your Action only once the character has spawned.

    You can do this either by having your WalkScript function run the ActionList itself once spawned, or by attaching a script to the NPC that uses its own Awake function to run an ActionList:

    using UnityEngine;
    using AC;
    
    public class RunActionListOnAwake : MonoBehaviour
    {
    
        public ActionListAsset actionListOnAwake;
    
        void Awake ()
        {
            actionListOnAwake.Interact ();
        }
    
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.