I want to enable/disable some components like trail Renderer during weapon attack battle event. Is it possible to target currently equipped weapon/armor gameobject and store it in selected data?

I tried this approach, it did not work. And after taking a peek at source code I don't thinks it's supposed to?

I can probably modify Select Equipment code to return game object but I wanted to see if there is a clean built in way to do this.

  • Ah, that would be a bit trickier I guess. I did not know you could spawn several copies of same equipment part.
  • You might not even need to use Selected Data for this.
    If you just want a trail renderer to be visible only during a swing, you could just use an Enable Component step.


    The Component Name just needs to be the particle effect component on the weapon object.
    Then make sure the path to the child object is correct.
    Note that this means your weapon prefab objects will have to use the same name for the same event to work.
    But if you just store them in different folders in the Project window it should be simple to keep them organized.
  • Thank you for the suggestion, but I think it would be easier to just add Helper script to combatant object and send message.

    I could probably also access the Equipment viewers on the Combatant to write custom event node, but with a quick scan I was not able to find where they are stored, Equipment viewer seems to be independent from Combatant and queries it to get data.

  • Another option would be to have a scripted event used in the character animation itself.


    That way the issue of references becomes much simpler.
    Simply have an event at the beginning of a swing to disable the necessary components and then another at the end to turn it off.
    You may also want to have a redundant turnoff event in your Idle animation just in case the attack animation is cancelled somehow.
  • I'm not sure if Unity fixed this in newer versions, but Animation events would not fire if there was a sudden drop in FPS or other similar issue, and animation jumped over event frame. Which was fine for something like calling a sound or activating one-off stuff.
    But with trailRenderer this means the weapon might get stuck with nasty effect.

  • Also an Animation Event that occurs during a transition won't fire, so watch out for that as well.
Sign In or Register to comment.