I have a raycast code which works perfectly in Editor builds (DebugGame Editor and Development Editor) but crashes in modes without editor.
example:
const auto* Actor = RV_Hit.GetActor();
UStaticMeshComponent* HitStaticMeshComponent = Cast<UStaticMeshComponent>(RV_Hit.Component.Get());
if (HitStaticMeshComponent)
{
UStaticMesh* StaticMesh = HitStaticMeshComponent->StaticMesh;
FStaticMeshLODResources& LODModel = StaticMesh->RenderData->LODResources[0];
FIndexArrayView Indices = LODModel.IndexBuffer.GetArrayView();
this is a raycast/hit check code fragment.
Indices is correct in editor modes, but NULL in standalone modes, therefore crashes in next lines where I want access it.
What I need to set/add in C++ for getting it work in standalone modes?
well maybe this is also an important info:
seems not only the mentioned boolean bNeedsCPUAccess is the problem, in standalone the entire IndexBuffer is NULL for that LOD. seems in standalone there is no initialisation for that buffer, therefore GetArrayView returns also with NULL (which works from IndexBuffer)
it is quite strange, as many UE sources use that method, and as I see, not only Editor related sources.
Could you provide some additional information about this issue?
What version of the Engine are you using?
Are you using the binary version of the Engine installed by the Launcher, or did you build the Engine from source code?
Does this happen only in your own project, or are you able to reproduce this in a new project? If so, could you provide the steps you are following to cause the crash to occur?
Can you provide the callstack and logs after the crash occurs?
Please see this page for any additional information that may be helpful.
Thanks for the reply.
Im using UE 4.4.3, but I had the same problem with previous versions (from 4.3.1). It is the binary version.
Callstack, logs attached.
[link text][1]
This source works well if I start the game with editor build (DebugGame Editor), ut doesnt work if I start it as standalone (DebugGame). The buffer is ok in the editor modes, but NULL in standalone (see Watch screen), so accessing it by index fails.
The mesh Im using for raycast is the standard UE sphere:
StaticMesh’/Game/Shapes/EditorSphere.EditorSphere
Im working in a small team, two other people has UE, and they experience the same crash on same line.
Create new C++ project: Code First Person, name as RayCastTest
Add Source Code from UE menu, select Player Controller as base class, name MyPlayerController
Edit sources with VS and add RHI, RenderCore to RayCastTest.Build.cs file
ReplaceMyPlayerController.h and MyPlayerController.cpp with attached sources
Add following lines to RayCastTestGameMode.cpp: include “MyPlayerController.h”, to the constructor: PlayerControllerClass = AMyPlayerController::StaticClass();
Start project with editor build
Open level blueprint and add raycast to mouse click according to attached screen save
Make breakpoint to line 68 (bool bDebug = true) in myplayercontroller.cpp
Build it with DebugGame Editor, run the project in UE, Play and click to a white staticmesh box, breakpoint should be triggered: Indices is valid
Cook in UE and then build it with DebugGame (standalone), run and click to same mesh: Indices is NULL
If you need further detail or sth not clear, pls let me know!
Thank you for providing the additional reproduction steps. I was able to reproduce everything down through step 9. However, in step 10 when I try to run the project from Visual Studio in DebugGame configuration, it hits a breakpoint when loading, so I can’t test for the crash that you were seeing.
I did see a different crash happening in DebugGame Editor if the Raytrace hit one of the walls of the level instead of first hitting a cube. It happens where HitStaticMeshComponent is created, so I don’t think it is related to the original issue (Indices has not been created yet).
Which breakpoint hit if you run without editor while loading?
OK catching 10 would be important, my debuggame build ran correctly from VS and stops only at the BP I set.
I assume cook done correctly there…
I attach all sources generated/modified in my project, maybe there is a difference…
Yeah the other crash is irrelevant, it is due to short/demo code, it is only for staticmesh actors (which type we use in our game), other actors not handled. link text
The breakpoint issue I was experiencing turned out to be unrelated to the issue you were seeing. It was something that was recently fixed internally, and isn’t something that should be a bother to you or other users.
After spending most of today trying to sort out the issue above, I was finally able to reproduce the issue that you described. I have a couple more tests I want to run tomorrow, and then I will be submitting a report to have this investigated further by one of our developers.
Unfortunately there isn’t a way for you to directly check the ticket. However, if you ever need an update on the status of the ticket, please feel free to ask for one here. Any new posts here will re-open this issue, and we can check the ticket and give you an update.
Currently, the issue is still under investigation.
As BigaC mentions, we don’t keep the index buffer CPU accessible outside the editor, to save memory. That is exactly what the bNeedsCPUAccess logic is doing. You should be able to change the logic though if you need access to the graphics triangles. Another option would be to ask the PhysX colliison mesh for the vertex (e.g. using PxMeshQuery::getTriangle).
Is that still true if the artist has supplied a separate collision mesh for the static mesh? Or is there always a per-poly collision mesh available? I.e. would going this route compel me to use per-poly collision meshes?
Artist supplied ‘simple collision’ is in addition to per-poly collision, you usually need both, and can choose which is used when you do the query. Hitscan weapons normally want to trace against actual visible geometry for example. The only time we don’t pass the graphics polys to PhysX is if you disable collision for a section in the Static Mesh Editor.