Developer Notes

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.

Steps to Reproduce
  1. Create a new project using the Code First Person template, no starter content. Name the project RayCastTest.
  2. Build the project in Visual Studio, Development Editor configuration.
  3. Open the project in the Editor.
  4. Add a new code class to the project derived from PlayerController. Name the class MyPlayerController.
  5. In the Build.cs file for the project add "RHI", "RenderCore" to the PublicDependencyModuleNames.
  6. In the .h file for the new Player Controller class, add the following lines:
    	UFUNCTION(BlueprintCallable, Category = Selection)
    	void Raycast();
  7. In the .cpp file for the new class, add the following code:
    #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)
    	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)
    	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;
  8. Set a breakpoint on the bool bDebug = true; line.
  9. In the RayCastTest.h file, change #include "EngineMinimal.h" to #include "Engine.h"
  10. In the RayCastTestGameMode.cpp file, add the following line to the constructor:
    	PlayerControllerClass = AMyPlayerController::StaticClass();
  11. Set the build configuration in Visual Studio to DebugGame Editor and start a new debug instance of the project.
  12. Open the Level Blueprint and create the setup seen in the attached image (levelbp.png).
  13. Press Play to play the game in the Editor.
  14. Move the mouse over one of the white static mesh cubes in the level and click.
    • If the raycast hits one of the walls or the floor before hitting a cube, a different breakpoint will trigger that is not being tested here.
  15. The breakpoint set in step 8 will trigger.
  16. In Visual Studio, note that the values currently set in Indices are correct.
  17. In the Editor, select File -> Cook content for windows
  18. Once the Editor has completed cooking content, close the Editor.
  19. Change the solution configuration in Visual Studio to DebugGame.
  20. Start a new debug instance of the project.
  21. Click on a white static mesh cube again.

The values shown for Indices are incorrect.

The values shown for Indices are the same as they were when playing in the Editor.

Have Comments or More Details?

Head over to the existing Questions & Answers thread and let us know what's up.

Login to Vote

By Design
ComponentUE - Gameplay
Affects Versions4.7
CreatedNov 14, 2014
ResolvedNov 25, 2014
UpdatedApr 27, 2018
View Jira Issue