Little improvement from my side cause of flexibility to TriggerTags

I have declared a EditAnywhere FName TriggerTag variable.

With that you can easily reuse the same Plate for other Trigger to activate or deactivate, f.e. crates or stone which could be set by the player.

to make it a lil bit more save when no TriggerTag is set i used an early return

		if (TriggerTag == "")
		{
			return;
		}
		else
		{
			for (int ActorIndex = 0; ActorIndex < OverlappingActors.Num(); ++ActorIndex)
			{
				AActor* A = OverlappingActors[ActorIndex];

				/*FString Msg = FString::Printf(TEXT("Name: %s"), *A->GetName());
				GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::White, Msg);*/

				if (A->ActorHasTag(TriggerTag))
				{
					TriggerActor = A;
					break;
				}
			}
			if (TriggerActor)
			{
				if (!Activated)
				{
					Activated = true;
					GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::White, TEXT("Activated"));
				}
			}
			else
			{
				if (Activated)
				{
					Activated = false;
					GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::White, TEXT("Deactivated"));
				}
			}
		}

I really don´t like anything string based hardcoded :wink:

1 Like

This is a good idea. Sometimes it is good to hard-code things - this would be when you’re working on a team where artists and level designers may be using the assets and you don’t want them breaking things. Adding in C++ hides this from them as opposed to enabling them to change via blueprint.

A few observations about your C++ code here which may help you in future.

The if statement has an else, but it is redundant because if the TrigggerTag is empty then you return. So, you can remove that.

The for loop can use a modern for (auto var : collection) - I think this should work in this case but you’ll have to try.

Lastly, the If statement outside the for loop - make a method out of this and call it passing A in as a parameter instead of Assigning TriggerActor before the break

None of this will really change how it works but it makes it simpler to follow. I hope this makes sense.

Just curious, but your name - B5?

1 Like

Hi beegeedee,

thanks for the looking over my code.
Your point is totally correct that the else is redundant, maybe it was late when i wrote it :wink:

the modern for loop was taught by the instructor that way, to this point i didn´t find a case that it wouldn´t work, but i will keep an eye on this.

Again many thanks for your input :slight_smile:

With B5 you are talking about Babylon5? I really loved this tv serie but nope the name doesnt come from this.
To be truthful, Seth only comes from my love of egypt mythology and when i had to create an name in WoW (about 15 years ago :wink: ) I had to add something to it and after some thinking it became “-reus”.

So since then i always used this pseudonym online anywhere and some of my digital friends, even they knew my real name never quit calling me Seth oder Sethreus.

Ah. That explains it. I got the name mixed up too. Meant zathrus.

Enjoy the course.

Privacy & Terms