Hi, I want the actors to be dropped on the ground when they are spawned in the level.
using this blueprint I can do it without any problem but how to do this using C++?
Here I am doing this by object collision channel for the ground which blocks anything.
So, the only thing you need to do, is find a C++ equivalent of these BP functions. The LineTraceForObjects in C++ is inside Kismet/KismetSystemLibrary.h and called UKismetSystemLibrary::LineTraceSingleForObjects (UKismetSystemLibrary::LineTraceSingleForObjects | Unreal Engine Documentation). SetActorLocation and GetActorLocation have same names in C++, MakeArray is TArray<TEnumAsByte<EObjectTypeQuery>> Arr = {your channels}. Others are simple struct member access and math transformations.
The only difficulty is with EObjectTypeQuery type - you can convert ECollisionChannel to EObjectTypeQuery using UEngineTypes::ConvertToObjectType from Engine/EngineTypes.h (UEngineTypes::ConvertToObjectType | Unreal Engine Documentation).
I solved the Issue, but I have one problem, I am unable to create/access my own collision channel by the name Land , and after all everything works using the channel WorldStatic while it blocks everything too. But I want to use my own channel.
Your own channel is one of ECC_GameTraceChannelN (N is a number), and N is similar to order you added your collisions (for example, if your collision is the only custom channel, N = 1, youe channel is editor is ECC_GameTraceChannel1 in C++, if you add it as a second custom channel - it’ll be a ECC_GameTraceChannel2). You can create macro #define MyTraceChannelName ECC_GameTraceChannelN and use it instead of ECC_GameTraceChannelN if you want.
Also, does this code compiles? For example:
FHitResult is a parameter for LineTraceSingleByChannel (passed by a reference FHitResult&). And after that, you just access member using . (For example, FHitResult MyHit; FVector MyLocation = MyHit.Location;).
Translate BP to C++ means understanding your BP code logic and ability to reproduce it’s logic in C++. I suggest you to find some C++ basics tutorial - it’s difficult to write C++ code without knowledge of syntaxis.