Forum rules - please read before posting.

Altering Component Variables without Constant ID

I'm building on the enemies from the survival horror / combat package but since the enemies are basic and just meant as examples, I'm trying to damage them (and do other stuff) using action list assets as I'm also using a different weapon system rather than the one from the package.

I am struggling to check and/or set the health component variable though, I can't figure out the way to do it without having to reference the Constant ID - obviously this is not the way to go as it would mean having to setup an actionlist for every single enemy. I have tried following and adapting the tutorial video (the one with the lights and levers) in which parameters are used, but I can't seem to get my head round it for my use case.

I've started an action list for it (see "Action list start" image), but I keep getting this;

The 'Variable: Check' Action halted the ActionList because it cannot find the Component Variable with an ID of 0
(From Action #0 in ActionList 'Mutant_TakeDamage')


Action list start

So, I need to:
1: Tell the Action list which enemy game object to effect
2. Check and/or set the Health component variable of that enemy

Comments

  • The ActionList itself looks fine - it's down to how/when the parameter values are assigned.

    Are you using scripting, the ActionList: Run Action, or some other means to set the parmeter values?

  • This is where the confusion is for me, I was under the impression that the parameter values were copied from the variable or game object.

    But, I tried using the action list on scene start component to set the parameters like in the levers tutorial, and it worked that way - the action list played, though still referencing constant ID. However, in that action list I have sounds and animations playing so it's not suited to having it fire on scene start.

    So to start with, what would you say is the best way to go about setting these parameters (the enemy and the health component variable)?

  • You'd want to set them at the same time you run the ActionList. How are you currently running it?

    Typically such dynamic content is set via e.g. the Set Interaction Parameters component, which lets you set values based on a Hotspot interaction, but in the case of an enemy damage system I'd expect you'd invoke it through script.

    You can set parameter values through script just beforehand, i.e.:

    public ActionListAsset actionListAsset;
    public int healthVariableID;
    
    public void Run(GameObject hitEnemy)
    {
        actionListAsset.GetParameter("Health").SetValue(hitEnemy.GetComponent<Variables>(), healthVariableID);
        actionListAsset.GetParameter("Mutant").SetValue(hitEnemy);
        actionListAsset.Interact();
    }
    
  • How are you currently running it?

    The weapon system I am using fires bullet projectiles, the colliders they hit have Unity Events you can fire when hit, so with that you can call interact on Action Lists.

    So, with your script here I have made a component called Set Parameters. I have put this on my enemy and filled in the fields. When a bullet hits, it calls the SetParameters.Run to set the parameters, then calls interact on the Take Damage action list asset.

    This seems to be working apart from one new issue - it is doing double damage. You see in my imgur image (how do we post images here directly btw?) how 25 is supposed to be deducted from the health component? Well 50 is being deducted. I do not know why, perhaps the action list is being run twice for some reason?
    (It is not related to that bullet system as the same thing happens if I just use "Run Now" in the inspector).

  • Add an ActionList: Comment Action to the top of the ActionList, to print some debug text to the Console when run - that should give the clearest check that it's not being run twice. Bear in mind that the code snippet above also runs the ActionList.

  • Bear in mind that the code snippet above also runs the ActionList.

    That was it Chris, thank you.

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.