Virtual Override Method not calling in one instance, but works in others

Below is a script that is activated when an enemy attacks, the issue I’m having is the Do override function never activates. The enter function works just fine and plays the animation though. I’ve used a script like this in my player and it has the same functionality that works just fine. Also double checked that there isn’t an issue with the bool because if I place the code in the enter method it works, just not sure why my Do function isn’t being activated when I’ve used this same methodology before.


    [SerializeField] List<GameObject> children = new List<GameObject>();

    [SerializeField] float attack1FrameDuration;

    [SerializeField] int attackFrame;

    bool sequenceStarted = false;
    public override void Enter()
    {
        animator.Play(anim.name);
    }

    public override void Do()
    {
        if (!sequenceStarted)
        {
            StartCoroutine(AttackSequence(attack1FrameDuration, attackFrame, 100));
        }
        if (!posCheck.grounded || npcHealth.hit)
        {
            StopAllCoroutines();
            StartCoroutine(DeActiveate());
            isComplete = true;
            sequenceStarted = false;
        }
    }
    public override void Exit()
    {

    }

Where are you calling Do() from? I don’t see a call site in the code above.

1 Like

That’s a great question and thanks for the quick response, to be completely honest I’m a victim of a youtube tutorial. Apparently this do function is called like update only after Enter is called and the script is activated. I thought the same thing and can’t find any support of it anywhere else, but the weird thing is it works in my player controller, and there is no direct call through any of my scripts, it’s setup is exactly like this. I did happen to fix the problem by just changing it to an update function with an instantiate bool, so the issue is technically solved, I’m just very lost on how Do continues to work in my player script.

Fair enough… it happens. But all is not lost. You can always go back and do Step #2 below:

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.

Well, something calls it. Code? An inspector function? An animation event? Something calls it.

Here is a longer-form version of what I already posted above:

Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

How to do tutorials properly, two (2) simple steps to success:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!

If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

I like this guy’s “Can I … ?” approach.

Imphenzia: How Did I Learn To Make Games:

Thanks Kurt! I really appreciate the help!

I ended up finding out where Do was being called, just in the update function in the state machine where the active state is set, now I see the function of the Do method is to only update the active state, which is really the same functionality with the technique I used to use update and a control boolean. Again really appreciate the help and I’ll take this as an opportunity to be more careful when following a tutorial.

1 Like