OnItemStartUse Event calls twice

Grannyboy

Active member
I have an listener to the event "OnItemStartUse" with the following script:
1652298357739.png
Using the melee weapon i get two debug log statements with 1 second apart:
1652298397414.png

Why does the event get called twice? I only want it to get called once
 
The event is called when starting and stopping the item use. The difference is that the bool "use" is set to true/false. Your code does not check for that.
 
The event is called when starting and stopping the item use. The difference is that the bool "use" is set to true/false. Your code does not check for that.
Thank you sir!
I will update the thread with solution for future developers!

Maybe im going off topic on my own thread, but what would be a better solution for spawning a particle system on a melee use?
I want sword slashes as particle system to show on each hit.

Edit: I got sequence hits 1,2,3,4 and preferably I would like different particle systems for different melee swing animations. Any out of the box solutions for this?
 
Last edited:
The melee weapon component has a trail attribute you can add a particle system prefab to. It does not allow to add different prefabs, but you could write your own component that spawns different particle systems, and add this component to the trail field. Take a look at the melee weapons in the demo.

If you are more talking about impact effects, you can take a look at the surface system. This allows to spawn different effects based on the impacted surface. This can also be explored in the demo.
 
The melee weapon component has a trail attribute you can add a particle system prefab to. It does not allow to add different prefabs, but you could write your own component that spawns different particle systems, and add this component to the trail field. Take a look at the melee weapons in the demo.

If you are more talking about impact effects, you can take a look at the surface system. This allows to spawn different effects based on the impacted surface. This can also be explored in the demo.
Thank you for the elaborate answer! Ill check the trail out but I dont think it suits my specific sword slashes properly.
 
One more thought about this issue. In the melee weapon script there is a option to set states on each of the different melee attacks, also shown in the tutorial video on melee weapons where IK is disabled on the non dominant hand.

Is it possible to write a script that listens to this states?
And throught this script play my specific particle system for the specific melee attack which states ill set on the melee weapon script.
 
Yes, you can set a state for each animator audio state. You can then define a presets for each state on your melee weapon which assign different trail prefabs.

You can listen to the state changes through the event system. But I don't see a need for that in your case, as the different trails/particle effects are assigned through the presets. There is an OnStateChange event:https://opsive.com/support/document...ller/programming-concepts/events/event-names/
 
Yes, you can set a state for each animator audio state. You can then define a presets for each state on your melee weapon which assign different trail prefabs.

You can listen to the state changes through the event system. But I don't see a need for that in your case, as the different trails/particle effects are assigned through the presets. There is an OnStateChange event:https://opsive.com/support/document...ller/programming-concepts/events/event-names/
That sounds like a viable solution! I will dig into it, thanks Christian!
 
I have a working solution now! But its not really concerning this thread so ill make a new thread explaining the issue and the solution in case someone else ever run in to this problem.
 
Top