[Feature Request] Muzzle Flash Probability

Absent83

Member
@Justin, Can you add probabilty to show muzzle flash like a probabilty of surfaces effects?

It`s needed for high-rate weapons for mobile games.
 

Justin

Administrator
Staff member
On the Shootable Weapon component you can disable Pool Muzzle Flash. This will then only use a single muzzle flash so you don't have a bunch of effects alpha blended together.
 

Justin

Administrator
Staff member
I've edited your post. There's no need to post entire files from the asset - this is a public forum so there are users here who don't have a license to UCC.

For bug reports please follow this post.
 

Absent83

Member
@Justin, see comments:

Code:
public void Show(Item item, int itemActionID, bool pooled, UltimateCharacterLocomotion characterLocomotion)
        {
            ...
            m_Color.a = m_StartAlpha; // <=== set m_Color.a
            ...

            // The muzzle flash may be inactive if the object isn't pooled.
            if (!m_Pooled) {
                m_GameObject.SetActive(true);  // <=== enable GameObject
            }
        }


private void OnEnable()
        {
            m_Color.a = 0; // <=== reset m_Color.a to 0
            ...
        }


private void Update()
        {
            if (m_Color.a > 0) {  // <=== m_Color.a == 0 at the first frame cause OnEnable resets it
                ...
                }
            } else {
                if (m_Pooled) {
                    ...
                } else {
                    m_GameObject.SetActive(false);  // <=== disable GameObject
                }
            }
        }
 

Absent83

Member
@Justin , Sorry for entire code.
Have you read comments in the next post?


1. Character controller variant: UCC 2.1.5
2. Unity version: Unity 2018.2.19f1 (64-bit)
3. Bug description: Muzzle Flash does not appears in not pooled mode.
4. Steps to reproduce: switch off pooled mode for muzzle flash and try to press fire button several times.
5. The full error message (if any): No error message.
 
Last edited:

Justin

Administrator
Staff member
Good catch. Within MuzzleFlash.Show move the following to the top of that method:

Code:
            // The muzzle flash may be inactive if the object isn't pooled.
            if (!m_Pooled) {
                m_GameObject.SetActive(true);
            }
 

Absent83

Member
Sorry, but I do not understant, what is the differecne where this code is located?

After the m_GameObject.SetActive(true), OnEnable occurs and m_Color.a = 0, so in update if condition m_Color.a > 0 equals false.
 

Justin

Administrator
Staff member
The difference is that OnEnable will be called before the color is set to the start color so it fixes the order of execution.
 

Absent83

Member
Thank you, I thought, that OnEnable called on the next frame after Show(). I mistake. I will wait for the next update with this fix.
 

Absent83

Member
Now I see, that there is only one istance of the muzzle flash.

Maybe you can add a serialized private field to control the update method:

1. Execute changing of muzzle-flash in update method every second/third or more frame (preffered choice)
OR
2. Execute changing of muzzle-flash in update with probability.

I think that there is no need to perform a muzzle flash change every frame. Or you cas set this field to change muzzle flash every frame at any time, if you need :)
 
Top