How do I make each enemy have a different particle color?

I have a simple script I’m working on for a game I’m contributing to that will create a color from random floats and then make sure the resulting color is not too close to black.

The way the game is set up, each enemy ship is equipped with weapons which are equipped with bullets, and each bullet is an actor that has a particle effect component attached to it. Ideally, I should be able to determine a color for each enemy’s bullets to use, and use that for all bullets fired from that enemy’s guns. However, when I place my script on the bullet actor itself, each bullet fired from it is a random color, a new color for every single time it fires. Instead, I want a random color that is used for ALL of that particular enemy’s bullets, for example, if the script decides that this enemy’s bullets will be green, every bullet it fires will be green.

My first assumption was that I should put the script on the weapon, that way an enemy who is equipped with this weapon will have bullets that are all that color. However, because of the way the weapons and bullets are set up, I don’t know how to access the particle effect from within the weapon to change the color. Furthermore, some enemies may be equipped with two instances of this weapon, and they would have different colored bullets firing from each gun, which is undesirable. I would prefer if the enemy chooses its color and then applies that color to all of the guns of this type that it owns.


RC_ROF is a weapon component that can be attached to an enemy pawn. It will find the appropriate socket on the model and attach itself there, allowing the enemy to fire. When it fires, it will fire the actor in its Munition field, which is a bullet called energyPeashooter. This actor has a root mesh (which can be made invisible if desired) and collision and can be equipped with a particle system component to display an effect as it travels through the air.

I want to be able to generate a random color and assign that color to the particle effect on energyPeashooter, without having it make a new color every time RC_ROF fires. How can I access the particle component from a higher level so that the color is only generated once for each enemy?

  • When enemy is spawned, generate a color once and save it into a variable;
  • In the bullet BP, create a color variable and set it to be exposed on spawn;
  • When the ship spawns a bullet, feed the ship color to the bullet color;
  • When the bullet hits and spawns a particle system, set particles color for the spawned system.

P.S. In my experience, making colors from random values is not the best way to go. 75% of them end up being undistinctive dirty grey-ish. Better create an array of 10-20 predefined colors and pick one at random.