How do we know which parameters are optional?

When we took a look at the header file of GameplayStatics.h we saw that the function SpawnEmitterAttached takes in 10 parameters. However, we are only passing in 3 of them.
Is there a way to know which are optional and which are required?
I’m assuming the rest of the parameters are using their default values then.

Also, is it possible to skip parameters? Let’s say we only want to pass in parameters 1 und 5 and rest can use their default value. Do we have to pass in the first 5 or can we skip 2 - 4? I guess that would cause problems if there are multiple parameters of the same type.

1 Like

UGameplayStatics::SpawnEmitterAttached(MuzzleFlash, Mesh, TEXT("MuzzleFlashSocket"));

and if you right click in eg Visual Studio and go to declaration:

static UParticleSystemComponent* SpawnEmitterAttached(class UParticleSystem* EmitterTemplate, class USceneComponent* AttachToComponent, FName AttachPointName = NAME_None, FVector Location = FVector(ForceInit), FRotator Rotation = FRotator::ZeroRotator, FVector Scale = FVector(1.f), EAttachLocation::Type LocationType = EAttachLocation::KeepRelativeOffset, bool bAutoDestroy = true, EPSCPoolMethod PoolingMethod = EPSCPoolMethod::None, bool bAutoActivate=true);

You’ll see most include = default value.

When you’re coding, the IDE is your friend. If you’re using Visual Studio Code or a different code editor then I don’t know what it will do as its not an IDE and may offer less help.

But it helps to learn how to use an IDE to view the development library code. The UE4 documentation doesn’t look as helpful here and makes it look like all have to be supplied but it is not the code. The code is final. You cannot do what the code doesn’t allow and documentation can be wrong or poor at times.

http://www.cplusplus.com/forum/beginner/24372/

https://www.w3schools.com/cpp/cpp_function_default.asp

Someone else can fill it in further.

The declaration looks different for me. Maybe it’s a different version of Unreal.
The only parameters that have a default value are bAutoDestroy, PoolingMethod and bAutoActivate.

static UParticleSystemComponent* SpawnEmitterAttached(class UParticleSystem* EmitterTemplate, class USceneComponent* AttachToComponent, FName AttachPointName, FVector Location, FRotator Rotation, EAttachLocation::Type LocationType, bool bAutoDestroy = true, EPSCPoolMethod PoolingMethod = EPSCPoolMethod::None, bool bAutoActivate=true);

That’s why I was wondering why the other parameters are not required when calling the function.

I’m using 4.25, btw.

Oh yes. I’m using UE5. Sorry, forgot about that lol.

Not sure if the function was overloaded in previous UE versions. The go to declaration should be smart enough to go to the right function in that case but maybe not.

Example you can try:

You can put into your project code…

void TestA(int a, int b, int c = 0) {

}

void TestA(int a, int b = 0) {

}

void TestB(int a, int b, int c = 0) {

}

Then use…

TestA(0) // building will succeed

TestB(0) // building will fail because the code cannot do this

Because when the code can do it then there’s a valid reason in the code.

You could also look at the header also.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms