ShooterGame - How were impact effects made? Spawning stuff

I’m going through the ShooterGame source in Visual Studio to see how a particle effect is spawned, I thought it was a good enough task to start with.

I see the relationship between the Bluepint WeapGun_Impacts and the ShooterImpactEffect.cpp

I guess I’m asking which came first? The blueprint or the .cpp file.

It looks like you don’t call out the path name to a resource to spawn it like in UE3. Can you spawn something off it’s name? Lets say I create a particlesystem, can I spawn it from C++ directly, or do I have to make a blueprint that allows that functionality.

Basically, in the snippet below, could ImpactFX be replaced by a literal string for the path of the effect? Or, is it required to make a blueprint with a getter function that returns it?

// show particles
UParticleSystem* ImpactFX = GetImpactFX(HitMaterialType);
if (ImpactFX)
{
UParticleSystemComponent* FXComp = UGameplayStatics::SpawnEmitterAtLocation(this, ImpactFX, GetActorLocation(), GetActorRotation());
if (FXComp)
{
// add to component list for bAutoDestroyWhenFinished detection
Components.Add(FXComp);
}
}

Sorry if this is a stupid question and obvious.

I don’t have it in front of me to look into, but I am guessing what you are seeing is a class being defined in C++ and then Blueprints being made using that class as the parent. The C++ class would have to exist first. Creating Blueprints does not cause C++ code or headers to be generated.

You can definitely create instances in C++. You reference assets in C++ code in pretty much the same way you would in UnrealScript in UE3. There is some basic info over this on this page:

Assets and Packages

The main difference is that you used to specify a path as Package.Group.AssetName, whereas now you would use the relative path to the asset prefixed with Engine, Game, etc. depending on where the asset is located. For example, if the asset is in your project’s Content folder, you would prefix the path with Game: i.e. /Game/Path/To/UAsset/AssetName. If it is an asset in the Engine/Content folder, you prefix it with Engine.

In UnrealScript, you would usually reference these in the defaultproperties. In C++ in UE4, you do this in the class constructor. Again, there is some basic info (though probably in need of serious updating) about this on the page below:

Asset References

Looking at examples of constructors in the samples provided will give you a more accurate idea of the exact method and syntax to use until we get the documentation up to date.

Or, as I suspect the impact effects example you mentioned is doing, you can declare a property in the C++ class to reference the asset to use and then create one or more Blueprints parented to that class and just set the property on the Blueprint. This is almost identical to how Archetypes worked in UE3, and it means you don’t have to create multiple classes in C++ just to set different property values. You just create a Blueprint for each set of property values and spawn those instead.

Thanks for your answer. I’m starting to get it. I added the property to the character, then when I opened up the blueprint it was there. Spawning a particle effect on jump is the result. It seems trivial, but maybe I should put it as a tutorial on the forum.

pinkonjump.jpg

That would be great !