Developing Particle Module

Hello,

I am following the steps on Particle Module Technical Guide to create a cusotomized particle module in C++.

I started out with the Add Code wizard (in UE 4.7.1) and chose ParticleModuleColor as the base class (since ParticleModuleColorBase was for some reasone not selectable) and named the new class MyParticleModuleColor. Then when the new classes were being created an error message popped up:

Failed to add class MyParticleModuleColor. Failed to automatically hot reload the MyCppTestProject module.

But the .h and .cpp files had already been created despite the error message. So I went to VS 2013 and tried to build the project and got the errors:

1>------ Build started: Project: MyCppTestProject, Configuration: Development_Editor x64 ------
2>------ Skipped Build: Project: UE4, Configuration: BuiltWithUnrealBuildTool Win32 ------
2>Project not selected to build for this solution configuration 
1>  Compiling game modules for hot reload
1>  Performing 3 actions (4 in parallel)
1>  MyParticleModuleColor.cpp
1>  MyCppTestProject.generated.cpp
1>C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\Engine\Classes\Particles/ParticleModule.h(372): error C2061: syntax error : identifier 'UDistributionFloat'C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\Engine\Classes\Particles/ParticleModule.h(372) : error C2061: syntax error : identifier 'UDistributionFloat'
1>  
1>C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\Engine\Classes\Particles/ParticleModule.h(382): error C2061: syntax error : identifier 'UDistributionVector'
1>C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\Engine\Classes\Particles/ParticleModule.h(382): error C2061: syntax error : identifier 'UDistributionVector'
1>C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\Engine\Classes\Particles/ParticleModule.h(580): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\Engine\Classes\Particles/ParticleModule.h(580): error C2143: syntax error : missing ',' before '*'
1>C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\Engine\Classes\Particles/ParticleModule.h(580): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\Engine\Classes\Particles/ParticleModule.h(580): error C2143: syntax error : missing ',' before '*'
1>C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\Engine\Classes\Particles/Color/ParticleModuleColor.h(15): error C2079: 'UParticleModuleColor::StartColor' uses undefined struct 'FRawDistributionVector'
1>C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\Engine\Classes\Particles/Color/ParticleModuleColor.h(19): error C2079: 'UParticleModuleColor::StartAlpha' uses undefined struct 'FRawDistributionFloat'
1>C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\Engine\Classes\Particles/Color/ParticleModuleColor.h(15): error C2079: 'UParticleModuleColor::StartColor' uses undefined struct 'FRawDistributionVector'
1>C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\Engine\Classes\Particles/Color/ParticleModuleColor.h(19): error C2079: 'UParticleModuleColor::StartAlpha' uses undefined struct 'FRawDistributionFloat'
1>  -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: C:\Users\Me\Documents\Unreal Projects\MyCppTestProject\Binaries\Win64\UE4Editor-MyCppTestProject-7247.dll
1>  Cumulative action seconds (8 processors): 0.00 building projects, 0.80 compiling, 0.00 creating app bundles, 0.00 generating debug info, 0.00 linking, 0.00 other
1>  UBT execution time: 4.14 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command ""C:\Program Files\Epic Games\4.7\Engine\Build\BatchFiles\Build.bat" MyCppTestProjectEditor Win64 Development "C:\Users\Me\Documents\Unreal Projects\MyCppTestProject\MyCppTestProject.uproject" -rocket" exited with code -1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 1 skipped ==========

Is there a way to fix the problems in UE Editor and VS? And why cannot ParticleModuleColorBase be selected as a base class?

Thank you in advance.

Hi there team at Epic!
I’ve been experiencing this particular issue as well. I’m using perforce, and I think that is a part of the equation. Please let us know at your earliest convenience whether this is a bug or if there is a tricky way around it that we haven’t quite figure out.

You guys are awesome, and I love your work, keep it up!

If you want to derive a particle module classes you have to export them from the engine DLL by adding ENGINE_API modifier:

class ENGINE_API UParticleModuleColorBase : public UParticleModule

You have to add this too in the UParticleModule, additional in this class remove MinimalAPI:

UCLASS(editinlinenew, hidecategories=Object, abstract)
class ENGINE_API UParticleModule : public UObject

and by default some of the UParticleModule methods are marked with ENGINE_API, remove ENGINE_API modifier from them.

And remember to add:

#include "ParticleDefinitions.h"

in your derived ParticleModule cpp file.

Hope this will help you:)

Regards

Pierdek

Thank you, Pierdek! Your solution works for me - Exposing the classes from the engine’s source and referencing this modified version from a game project. Though in the future it is up to the UE team to decide whether to export these classes in release versions or not, for now this solution somehow maintains the independence of the added functionality from the engine.

As the discussion goes in another thread (Adding new .h/.cpp files to engine source - Programming & Scripting - Epic Developer Community Forums), an alternative method would be adding the feature directly inside the engine without changing export modifiers.

Best regards,
D

Hi,

I’ve been trying the same thing here and I must say I’m a little lost as to how to get this work.

I am following the and the generated result of this wizard doest compile. With much the same issues as in the first post here. I’m very new to C++ but have several years of C# experience. (not that thats helping)

I’ve no idea how to apply Pierdek’s suggestions here.

Do the changes you mention need to go in the UE4 code base or my game projects code?

The broken starting point that the wizard gives are:

MyParticleModuleColorTest.h:

#pragma once
#include "Particles/Color/ParticleModuleColor.h"
#include "MyParticleModuleColorTest.generated.h"

/**
 * 
 */
UCLASS()
class EFFECTSTESTER_API UMyParticleModuleColorTest : public UParticleModuleColor
{
	GENERATED_BODY()
};

and

MyParticleModuleColorTest.cpp:

#include "EffectsTester.h"
#include "MyParticleModuleColorTest.h"

Thanks in advance to anyone who can help here,

Regards

Hi Epic. I would appreciate if it will be possible to extend particle modules in the game and not the engine itself. It is a hard restriction somehow.

Can’t find the Particle Module Technical Guide in the Unreal documentation anymore. Does anyone know why they removed it?

Here is my way how to add particle module with out editing engine source (works for unreal 4.22)

First create abstract class which will tell engine category of your modules, let it be “Wind” group:

#pragma once

#include "CoreMinimal.h"
#include "Particles/ParticleModule.h"
#include "ParticleModuleWindBase.generated.h"

/**
 * 
 */
UCLASS(editinlinenew, hidecategories = Object, abstract, meta = (DisplayName = "Wind"))
class YOURAPP_API UParticleModuleWindBase : public UParticleModule
{
	GENERATED_BODY()
	
};

Then create class derived from this to implement actual behavior:

#pragma once

#include "CoreMinimal.h"
#include "ParticleModuleWindBase.h"
#include "ParticleDefinitions.h"
#include "ParticleModuleWind.generated.h"

/**
 * 
 */
UCLASS(editinlinenew, hidecategories = Object, meta = (DisplayName = "Constant velocity"))
class YOURAPP_API UParticleModuleWind : public UParticleModuleWindBase
{
	GENERATED_UCLASS_BODY()

	/**
	*  How much wind affect particle [0-1]
	*  0 - particles not affected by wind
	*  1 - particle speed equal wind speed
	*/
	UPROPERTY(EditAnywhere, Category = Velocity)
	float Amount;

	/** Initializes the default values */
	void InitializeDefaults();

	//~ Begin UObject Interface
#if WITH_EDITOR
	virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
#endif // WITH_EDITOR
	virtual void PostInitProperties() override;
	//~ End UObject Interface

	//~ Begin UParticleModule Interface
	virtual void Spawn(FParticleEmitterInstance* Owner, int32 Offset, float SpawnTime, FBaseParticle* ParticleBase) override;
	//~ Begin UParticleModule Interface

	/**
	*	Extended version of spawn, allows for using a random stream for distribution value retrieval
	*
	*	@param	Owner				The particle emitter instance that is spawning
	*	@param	Offset				The offset to the modules payload data
	*	@param	SpawnTime			The time of the spawn
	*	@param	InRandomStream		The random stream to use for retrieving random values
	*/
	void SpawnEx(FParticleEmitterInstance* Owner, int32 Offset, float SpawnTime, struct FRandomStream* InRandomStream, FBaseParticle* ParticleBase);
};

It will create new group in editor with single module “Constant velocity” available there