Thank you for this awesome thread and the work you’ve been sharing.
I’ve currently run in to a snag and I’m wondering if anybody else is having the same problem. If I create a blueprint to run line traces agaisnt the dynamic meshes I’ll eventually get the following crash:
I’ve confirmed that in other projects without the dynamic mesh instances that I cannot reproduce the crash. I’ve attempted to debug the issue by running the engine from VS with debugging on, however instead of a break it simply freezes and crashes to desktop. I’d be grateful if someone else who’s implemented the dynamic meshes would try and run a few line traces to see if they see the same thing. Otherwise it might be something on my side unrelated to the dynamic meshes. Here is my blueprint for reference:
The trace will fire and show up on the meshes a few times but eventually crash. Sometimes it crashes early other times I have to spam it about 20-30 times to get it to crash.
Ok, I’ve got a pretty good lead on my problem. I seem to have found a solution that works for me, but I don’t think it’s really 100% correct.
The crash was being caused from the following location in the engine in the SetHitResultFromShapeAndFaceIndex() function in Source\Runtime\Engine\Private\Collision\CollisionConversions.cpp
// @fixme: only do this for InGameThread, otherwise, this will be done in AsyncTrace
if ( IsInGameThread() )
{
// This function returns the single material in all cases other than trimesh or heightfield
PxMaterial* PxMat = PShape->getMaterialFromInternalFaceIndex(FaceIndex);
if(PxMat != NULL)
{
OutResult.PhysMaterial = FPhysxUserData::Get<UPhysicalMaterial>(PxMat->userData);
FString name = OutResult.PhysMaterial->GetName();
}
}
else
{
//@fixme: this will be fixed properly when we can make FBodyInstance to be TWeakPtr - TTP (263842)
}
For certain FaceIndex the PxMat pointer returned from getMaterialFromInternalFaceIndex() would be garbage data (0xddddddddd…), this caused the deference PxMat->userData to crash the editor. It seems that for certain face indies we’re not setting the correct “Physics Material”…
After poking around in the GeneratedMeshComponent.cpp I found this (added comment to the suspicious line…)
bool UGeneratedMeshComponent::GetPhysicsTriMeshData(struct FTriMeshCollisionData* CollisionData, bool InUseAllTriData)
{
FTriIndices Triangle;
for (int32 i = 0; i<GeneratedMeshTris.Num(); i++) {
const FGeneratedMeshTriangle& tri = GeneratedMeshTris*;
Triangle.v0 = CollisionData->Vertices.Add(tri.Vertex0.Position);
Triangle.v1 = CollisionData->Vertices.Add(tri.Vertex1.Position);
Triangle.v2 = CollisionData->Vertices.Add(tri.Vertex2.Position);
CollisionData->Indices.Add(Triangle);
CollisionData->MaterialIndices.Add(i); //Why are we setting the Material index to the index of the triangle?
}
CollisionData->bFlipNormals = true;
return true;
}
After using the static mesh as a reference: UStaticMesh::GetPhysicsTriMeshData | Unreal Engine Documentation
It looks like this should be the “index of the material” and not the index of the triangle. My guess is we’re looking for materials at indexies that don’t exist.
Changing the line:
CollisionData->MaterialIndices.Add(i);
To this:
CollisionData->MaterialIndices.Add(0);
Seems to have solved the crashing issue. I’ve probably broken material-based physics collision but since I don’t need that for now I’m going to work with this. Hopefully someone who knows more about this stuff than me can figure out what the proper fix is.
I recently started on UDK to get a render of a procedural generation library. I tried to follow instructions on wiki but i get errors as i miss to link somethings. I suppose some obvious mistake from me but as i don’t dev in c++ long time ago, i’m appreciate some help.
[=HellFiveDay;94210]
I think it’s more easy to provide solution in the same post. Anyway i found my misstake, i use the version 4.3.0 and the code provided require 4.2.1.
[/]
I won’t be back to work on this before a couple of weeks, but I’ll update the wiki once I get my stuff up to date.
I am having an issue with this, I created a very simple mesh which is just a flat plane made from 4 triangles. The issue I am having is when using one of the starter textures the M_cobblestone_rough. The problem is when I move the camera left and right while looking down on the texture the bumpmap is changing the material like I am moving the camera in a different direction, up\down.
I tracked it down to the tangents in this part of the code:-
It looks a bit odd, but its at least moving correctly.
So question is am I doing something wrong or is this not the correct way to calculate the tangents? if needed I can record a short vid of the problem as its not that easy to explain.
[=;130794]
You need to call MarkRenderStateDirty from the component when you update any values to ensure that the Scene Proxy gets rebuilt with your new data.
[/]
My bad, the code is correct and there’s nothing special to do.
I had some stale code rebuilding the original mesh right after the code I use to modify it, thus voiding any modification
[=;131940]
I’ve just copied the code from the wiki example into my project and can create the lathed object in my map. However, it shows up with the default grey material rather than the black which it should have. My code includes the ColorComponent by Ryvar above but it makes no difference. Has anyone else seen this or can anyone offer any advice?
Cheers.
[/]
I also haven’t been able to change the color of the generated mesh.
Any help would be appreciate, as my project relies on custom lighting. If I can’t solve this, I will have to give up with unreal engine.
Also has anyone been able to create a physics composite shape for a simple cube yet? https://www…com/watch?feature=player_embedded&v=ZgQxWQ9oWoQ
I see (the magician) has i have had no luck… I guess ill keep researching… But I would love a tutorial, or some basic code for this, if anyone has succeeded. Custom physics would be amazing.
[=Deus0;136336]
I also haven’t been able to change the color of the generated mesh.
Any help would be appreciate, as my project relies on custom lighting. If I can’t solve this, I will have to give up with unreal engine.
[/]
Do you strictly need vertex color?
If not (and a material is enough for you) just declare the GeneratedMeshComponent as a UPROPERTY in the .h file and then you can assign a material to it through the editor or BluePrint.
Strictly yes.
Since I want to have custom lighting, or tinting per vertex.
I’m Using the code provided here on the forums and wiki:
Inside(GeneratedMesh.h):
Also, if you seen my links, the first one is the question I posted. The picture in it is the game im working on. As you can tell I’ve already added the material to it using cpp. I am trying to make lighting effects similar to BrickGame:
https://.com/AndrewScheidecker/BrickGame
I just need a basic example to work.
Also if you enable physics in the custom mesh:
It for some reason destroys the actor. Still not sure why.
Also debugged the ReceiveHit function, and the GeneratedMesh recieves a collision response from everything besides itself. So yes colllision works with custom mesh, but not with other custom meshes. That’s what i’ve discovered so far.
[=dmacesic;8842]
Anyone know how to make a mesh from vertices and triangles, attach it to an object and spawn it?
I looked into FDynamicMeshBuilder, but that’s only for drawing.
[/]
Are we still using GeneratedMeshComponent.h ?
I was hoping that I could just use the official . However, the editor is unable to locate CustomMeshComponent.h . The plug-in is for sure enabled. Have they not been able to get this working since March?