Visual and Sound FX Refactoring

Read Time:1 Minute, 8 Second

I refactored the Sound FX and Sound FX Handler into a generic Pooled Object and Object Pool Handler. Attaching the Pooled Object component to any Game Object allows it to be reused via the Object Pool Handler that creates it.

Pooled Objects deactivate themselves after a set amount of time.

An Object Pool Handler stores its recyclable objects inside a Game Object specified in the Inspector. Objects are created until the buffer reaches its capacity and then begins recycling the objects.

These two methods create and recycle the Pooled Objects. I had a bug in the Visual FX because I did not update the rotation while recycling the object.

Here you can see the Assault Rifle prefab variant. The two child objects Gunshot and Muzzle both have Object Pool Handler components. Gunshot generates Pooled Objects that are Sound FX while Muzzle generates Pooled Objects that are Visual FX.

The Run method either creates or recycles a Pooled Object.

I’m not a huge fan of the command being Object Pool Handler > Run. It isn’t very descriptive. One option would be to wrap the generic object in a more descriptive class:

Wrapper for Object Pool Handler.

This would show as Visual FX Handler > Play FX in the editor. It’s more readable but feels excessive. I may change it up down the line.

It does look significantly better.
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleppy
Sleppy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *