edited September 2016 in ORK Scripting
I'm trying to detect if the Move AI for a combatant is disabled via script.

I'm doing this because I have a custom Move AI script that is not disabled when a combatant's Move AI is disabled for a Game Event (and it has stuff in FixedUpdate() that interfere). Therefore, I want to disable this script's functions by putting them behind a check for a MoveAI block

I've done this so far:
private MoveAIComponent moveAI = null;
this.moveAI = this.gameObject.GetComponentInChildren<MoveAIComponent> ();
And I can use Debug.Log(this.moveAI) which returns (MyCharacter'sName (Clone) (OrkFramework.Behavior.MoveAIComponent) which suggests it's able to find the MoveAIComponent.

However, this.moveAI.blocked is always false, even though I'm executing a Game Event with Block Actor MoveAI (I also saw the Block MoveAI setting but I don't necessarily want to block ALL move AI). All of the relevant actors are in the Event Actor list.

In addition, this.moveAI.blocked is true if I do use the Block MoveAI setting instead of the Block Actor MoveAI.

What am I doing wrong and how can I fix it? :)

Incidentally, disabling the custom script associated with a MoveAI should probably be the default behavior, very un-intuitive that this is not the case and took a while to figure out what was going on with some issues :) This has bitten me twice, once for when a MoveAI controlled character becomes Player Controlled, and now with interference when MoveAI is disabled but the associated script is not.
Post edited by Juryiel on
  • You can check this attribute if the move AI is blocked globally:
    ORK.Control.MoveAIBlocked

    For individual components, there's the blocked field in the MoveAIComponent:
    moveAI.blocked

    If both are false (i.e. allowing move AI), it can still be blocked by the battle system. Here you'll need to check if move AI is allowed for the combatant:
    ORK.Battle.CanUseMoveAI(Combatant combatant)

    I can add a combined check available in the move AI component in the next update - all the checks are already done in the Update function of the move AI.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited September 2016
    Thanks for outlining that! That's great to know so I can check them all. However that doesn't answer my question :)

    My point is, I tried checking moveAI.blocked in the MoveAIComponent as described above and it is false when using the option Block Actor MoveAI in a game event. Why is this? If I use Block MoveAI option then moveAI.blocked is true as expected, but if I use Block Actor MoveAI then moveAI.blocked is false.

    Are you saying that for a Game Event with Block Actor MoveAI I need to check ORK.Control.MoveAIBlocked or ORK.Battle.CanUseMoveAI(Combatant combatant)? Because MoveAIComponent moveAI.blocked seems to be false in that case.

    Though, a combined check would be very useful.
    Post edited by Juryiel on
  • Block Actor Move AI only blocks the move AI of combatants that are added as actors. Did a quick check in the code and it should work as expected.

    Enabling Block Move AI will block the move AI globally, i.e. ORK.Control.MoveAIBlocked will be true, not the blocked field of the component.

    The next update will add a CanUse function to the move AI component which will check if the combatant can use the move AI or not. This is already implemented in the latest grid battles beta if you'd like to check it out.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Hmm I guess I'm not sure why it's not working.

    The combatants are added as actors, and I can tell that his has worked because the Game Event moves them around successfullyimage. I then use the code in my first post in a script that is attached to them, e.g. :
    private MoveAIComponent moveAI = null;
    this.moveAI = this.gameObject.GetComponentInChildren<MoveAIComponent> ();
    Debug.Log(this.moveAI)
    This returns false for 'Block Actor Move AI' and true for 'Block Move AI'.

    If it matters, they are added as Actors using type 'Member'.
    I'm not sure why this would be or what I should check.
  • Did a test and worked as expected - make sure you're checking combatants that are actual actors of the game event.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited September 2016
    I'm really unsure as to what I could check. If you did a test can you post the code you used? Maybe it will make my error clear.

    For me, I have a script, attached to the combatant named Evangeline, with the above code.

    With the code above to set this.moveAI, when I do

    Debug.Log(this.moveAI)

    I get back

    Evangeline(Clone) (ORKFramework.Behaviours.MoveAIComponent)

    Evangeline is one of the combatants who are actors of the Block Actor MoveAI event, and I can tell this is working because the event moves her around with Change Position blocks.

    And given that, in this case this.moveAI.blocked is returning false.

    I have the following options in the Event Settings:
    Blocking Event [Checked]
    Block Move AI [Unchecked]
    Block Actor Move AI [Checked]
    Block Control Maps [Unchecked]
    Block Player Control [Checked]
    Block Camera Control [Checked]
    Clear Block Steps [Checked] (though this makes no difference if I uncheck it)
    Us Main Camera [Checked]

    Can the Change Position blocks interfere with this check maybe? I guess if you're not aware of what could be going on, I'll try to run a simplified event and replicate this.

    Post edited by Juryiel on
  • Debug.Log(this.moveAI) will just write the component info to the console - and Unity will usually just print the name of the game object.
    If you want to print the move AI's block state, you could e.g. use this:
    Debug.Log(this.moveAI.name+": "+this.moveAI.blocked);

    Your event settings look correct - but keep in mind that blocking the actor move AI is only done while the event is running, e.g. if there's no wait or dialogue in there, the event is over instantly and no noticable block state occured.

    I can't give you my code, I just added more info to the inspector display for the move AI component, will be included in the next update.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited September 2016
    Yeah I know what the Debug.Log I posted does and shows info about the component :) I was using the Debug.Log(this.moveAI) to see that I have the right component selected for the right combatant who is an actor in the event, as you suggested.

    I then did Debug.Log(this.moveAI.blocked) as you suggested and as I said above, and it returns false during the event.

    So as far as I can see:

    1. I'm selecting the right MoveAIComponent for the right combatant, who is an actor in the event.
    2. moveAI.blocked returns false when using Block Actor MoveAI but true when using Block MoveAI.
    3. The actors in question are correctly set up to be actors in the event.
    4. The event is super long and has dialogue so it will stay active forever until I get through the dialogue, so it's not that the event is not running.

    Ok, since neither of us has any ideas then I'll see if I can run some more tests and get back to you.
    Post edited by Juryiel on
  • edited October 2016
    I had some time to try to debug this and what I found is that the 'Block Actor Move AI' is just not at all turning off the Move AI at all, even though the actor is correctly selected in the event settings (e.g., there are other blocks in the event that reference the actors and those work correctly in moving the actors around etc).

    Here are my settings:
    http://imgur.com/x15u5E9

    http://imgur.com/wL4LBID


    Does anything look off here? You can see that Member 0, 1, and 2 are set as event actors and that the Block Actor Move AI is checked but the move AI never shuts off. You can see that the event has dialogue which triggers for the correct actors (and also means that the event doesn't end quickly).

    I'm basically at a loss here
    Post edited by Juryiel on
  • edited October 2016
    Did a quick test with using member actors and it worked fine. Are your group members spawned in the scene at the start of the event?

    Since it's an autostart event, my guess is that it's started before ORK spawned the group/members, thus not disabling the move AI on them. Try using some delay on the autostart interaction, e.g. set Start After to 1.
    Post edited by gamingislove on
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited October 2016
    That is a great guess :)

    That fixed it. The fix itself is problematic because the event is supposed to trigger when a player enters a scene, and the player can enter from multiple different places so placing it at the spawn point is not quite right. Having it wait for some time until a spawn occurs is sort of odd and also I feel like I'm not in enough control of it (e.g. is it possible that 1s won't be enough if there's some lag or something?)

    Can the event be triggered only if the player is spawned already somehow? I guess the only thing I can think of is to have multiple identical events at each possible player spawn, then somehow destroy or deactivate them all when one is triggered (possibly via some sort of variable check)
    Post edited by Juryiel on
  • Well, the problem is that autostart events and player spawning happen pretty much at the same time (due to how Unity's script execution order), it's not like the player will be spawned only after several seconds.

    So a small wait (like 0.1-1 seconds) in an autostart event will ensure the player is spawned. Also, even if the player (group) is spawned a bit later than the event, they'll still be used in the events, but they spawn too late for blocking the move AI at the start of the event :)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Ah ok, then I should be able to make it work like I want :) Thanks! This has been bugging me for a long while, glad to finally get to the bottom of it.
Sign In or Register to comment.