We don't keep the index buffer CPU accessible outside the editor, to save memory.
GetArrayView is returning incorrect values in Standalone games. The correct values are returned when played in Editor.
public:
UFUNCTION(BlueprintCallable, Category = Selection)
void Raycast();
#include "GameFramework/PlayerController.h" #include "Runtime/Engine/Public/StaticMeshResources.h" #include "RayCastTest1Character.h" // ... void AMyPlayerController::Raycast() { FVector MousePos; FVector MouseDir; FRotator Rot; DeprojectMousePositionToWorld(MousePos, MouseDir); FHitResult RV_Hit(ForceInit); FCollisionResponseParams parms; FCollisionQueryParams RV_TraceParams = FCollisionQueryParams(FName(TEXT("RV_Trace")), true); FVector Start = MousePos; FVector End = MousePos + (MouseDir * 200000); RV_TraceParams.bReturnFaceIndex = true; RV_TraceParams.bTraceComplex = true; for (TActorIterator<ARayCastTest1Character> ActorItr(GetWorld()); ActorItr; ++ActorItr) { RV_TraceParams.AddIgnoredActor(*ActorItr); } DrawDebugLine(GetWorld(), Start, End, FColor(255, 0, 0), true, 10, 0, 1); bool DidTrace = GetWorld()->LineTraceSingle(RV_Hit, Start, End, ECollisionChannel::ECC_WorldStatic, RV_TraceParams); if (!DidTrace) { return; } const auto* Actor = RV_Hit.GetActor(); AStaticMeshActor* aactor = (AStaticMeshActor*)Actor; UStaticMeshComponent* HitStaticMeshComponent = aactor->StaticMeshComponent; FString stxt = Actor->GetActorClass()->GetName(); GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, stxt); if (HitStaticMeshComponent) { UStaticMesh* StaticMesh = HitStaticMeshComponent->StaticMesh; FStaticMeshLODResources& LODModel = StaticMesh->RenderData->LODResources[0]; FIndexArrayView Indices = LODModel.IndexBuffer.GetArrayView(); bool bDebug = true; } }
PlayerControllerClass = AMyPlayerController::StaticClass();
RESULTS:
The values shown for Indices are incorrect.
EXPECTED:
The values shown for Indices are the same as they were when playing in the Editor.
Head over to the existing Questions & Answers thread and let us know what's up.
0 |
Component | UE - Gameplay |
---|---|
Affects Versions | 4.7 |
Created | Nov 14, 2014 |
---|---|
Resolved | Nov 25, 2014 |
Updated | Apr 27, 2018 |