简体   繁体   中英

Sphere Trace For Objects in Unreal Engine C++

I added a new object channel named Point in Project Settings/Collision. Project Settings / Collision

I want to make Spehere Trace Single For Objects in C++. Basicly, i wanna do this in C++. Blueprint Code (It works)

I searched it for a while and i found this in DefaultEngine.ini: DefaultEngine.ini (Ln58)

This didnt work. Trace cant find the object. hit value is false:

    TArray<TEnumAsByte<EObjectTypeQuery>> ObjectTypesArray;
    ObjectTypesArray.Reserve(1);
    ObjectTypesArray.Emplace(ECollisionChannel::ECC_GameTraceChannel1);

    bool hit = UKismetSystemLibrary::SphereTraceSingleForObjects(GetWorld(), StartLocation, EndLocation, 500.f, ObjectTypesArray, false,
        IgnoredActors, EDrawDebugTrace::ForDuration, OutHit, true);

And this causes intellysense error: (No instance of overloaded function matches the argument list)

ObjectTypesArray.Add(ECollisionChannel::ECC_GameTraceChannel1);

What should i do? How can i add my own object channel to my TArray? Thanks a lot in advance.

The value you need to add to the array is

UEngineTypes::ConvertToTraceType(ECollisionChannel::ECC_GameTraceChannel1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM