Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Manipulating skeletal mesh vertex positions at runtime

Hey guys, I'm quite new to C++ programming (I much prefer C#) but I have a bit of experience with the engine itself (material creation etc.) and I've run into a bit of a problem. I'm trying to manipulate the vertex positions of a skeletal mesh at runtime without the editor. At first the engine crashed but I was able to fix that due to an array index being out of bounds. The real question I'm having is how can I update the mesh after the positions have been updated and to also fix a memory leak I'm having as well?

The code in question is here (no need for the header file as there's not much other than the void function).

 #include "UpdateVertex.h"
 #include "SkeletalMeshTypes.h"
 #include "Engine/Public/Rendering/SkeletalMeshLODRenderData.h"
 #include "Engine/Public/Rendering/SkeletalMeshRenderData.h"
 #include "Engine/SkeletalMesh.h"
 #include "Components/SkinnedMeshComponent.h"
 #include "Components/SkeletalMeshComponent.h"
 #include "Engine.h"
 void UUpdateVertex::Update(USkeletalMeshComponent* SkeletalMeshComp, int32 LodIndex)
     //Avoid running if no skeletal mesh was found
     if (!SkeletalMeshComp->SkeletalMesh)
         UE_LOG(LogTemp, Warning, TEXT("No skeletal mesh found!"));
     USkeletalMesh* SkelMesh = SkeletalMeshComp->SkeletalMesh;
     FSkeletalMeshRenderData* RenderData = SkelMesh->GetResourceForRendering();
     //Avoid crashing if index is higher than meshes LOD count
     if (LodIndex > SkelMesh->GetLODNum())
         UE_LOG(LogTemp, Warning, TEXT("LOD greater than index!"));
     FSkeletalMeshLODRenderData& LodRender = RenderData->LODRenderData[LodIndex];
     //Update every vertex position in every render section
     for (int32 j = 0; j < LodRender.RenderSections.Num(); j++)
         for (int32 i = 0; i < LodRender.RenderSections[j].GetNumVertices(); i++)
             LodRender.StaticVertexBuffers.PositionVertexBuffer.VertexPosition(i) += FVector(0.0f, 0.0f, 10.0f);
             UE_LOG(LogTemp, Warning, TEXT("Vertex position: %s"), *LodRender.StaticVertexBuffers.PositionVertexBuffer.VertexPosition(i).ToString());
     //FSkeletalMeshLODRenderData* LodRender = RenderData->LODRenderData;

I'm planning on separating the variables into an init function if that helps with the memory leak.

Product Version: UE 4.20
more ▼

asked Oct 30 '18 at 07:17 AM in Rendering

avatar image

6 1 3

avatar image LeStErThEmOlEsT Nov 02 '18 at 09:03 AM

Okay so I fixed the memory leak, turns out it was just the spamming of output logs in the 'for loop' that caused the RAM to go up like that. However, I still haven't found a way for the updated vertex positions to render...

avatar image HarryHighDef Nov 02 '18 at 09:23 AM

Do you only want to add 10 units on Z to each vertex?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question