Checking for Custom Trace Channel in C++

Hi everyone,

I’m looking for away to check in C++ if the user entered the appropriate Custom Trace Channel name used in one of the classes. Is there a way to do that?

Basically you pass in the ECC_GameTraceChannel with the correct index 1 -18, those are the custom ones you defined in the editor

For instance


FHitResult ATracer::DoTrace(FVector start, FVector end) {
	FHitResult result;
	FCollisionQueryParams qp;		
	FCollisionResponseParams resp;
	GetWorld()->LineTraceSingleByChannel(result, start, end, ECollisionChannel::ECC_GameTraceChannel1, qp, resp);

	return result;
}

Would hit the first custom trace channel

Remember to set trace to block for the custom channel on the object that is supposed to be tested against.

I’m using the ECC_GameTraceChannel ofcourse. I just want to make sure the user is setting up himself with the correct name.

Then I guess you could try

You can see binding between ECC_GameTraceChannelX & in-editor names in your project’s DefaultEngine.ini . They looks like:

+DefaultChannelResponses=(Channel=ECC_GameTraceChannel1,DefaultResponse=ECR_Overlap,bTraceType=False,bStaticObject=False,Name="MyCustomCollisionChannelName")

Then you can just create a header with

#define ECC_MyCustomCollisionChannelName ECC_GameTraceChannel1

how does this even answer the question ?

.h

// custom function to check channel name
public:
//#if WITH_EDITOR
	UFUNCTION(BlueprintCallable)
	bool CheckChannelCustom(FName NameToCheck);
//#endif

cpp

needed includes

#include "Engine/CollisionProfile.h"
#include "Engine/EngineTypes.h"
#include "Misc/ConfigCacheIni.h"


//#if WITH_EDITOR
bool ATraceActor::CheckChannelCustom(FName NameToCheck)
{	
	TArray<TSharedPtr<FName>> SharedNames;
	UCollisionProfile::GetProfileNames(SharedNames);		
	TArray<FString> OutMapList;
	
	const FConfigSection* MapListList = GConfig->GetSection(TEXT("/Script/Engine.CollisionProfile"), false, GEngineIni);
	if (MapListList)
	{
		for (FConfigSectionMap::TConstIterator It(*MapListList); It; ++It)
		{
			FName EntryType = It.Key();			
			FString EntryValue = It.Value().GetValue();			
			FString foundName = "";
			if (EntryValue.Contains("ECC_GameTraceChannel")) 
			{				
				FString startSearch = "Name=\"";
				FString endSearch = "\"";
				int32 startVal = EntryValue.Find(startSearch) + startSearch.Len();
				int32 endVal = EntryValue.Find(endSearch,ESearchCase::CaseSensitive,ESearchDir::FromStart,startVal);
				foundName =  EntryValue.Mid(startVal, endVal - startVal);

				if (foundName == NameToCheck) {
					return true;
				}

//				UE_LOG(LogTemp, Warning, TEXT(" foundName %s"), *foundName);
			};						
		}
	}	
	return false;
}
//#endif



Use GetcollisionResponseToChannal() In C++.

That will not check for a specific channel name.