x

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"

Some c++ code doesn't work on a packed game !

I'm using a custom node made by Rama, this is the code :

 bool UVictoryBPFunctionLibrary::GetStaticMeshVertexLocations(UStaticMeshComponent* Comp, TArray<FVector>& VertexPositions)
 {
     if(!Comp) return false;
     if(!Comp->IsValidLowLevel()) return false;
     
     //~~~~~~~~~~~~~~~~~~~~
     //                Vertex Buffer
     if(! Comp)                                     return false;
     if(! Comp->StaticMesh)                     return false;
     if(! Comp->StaticMesh->RenderData)     return false;
     if( Comp->StaticMesh->RenderData->LODResources.Num() < 1) return false;
     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
     //~~~ End of Pointer Safety Checks ~~~
     
     //~~~~~~~~~~~~
     VertexPositions.Empty();
     //~~~~~~~~~~~~
     
     FPositionVertexBuffer* VertexBuffer = NULL;
     VertexBuffer = & Comp->StaticMesh->RenderData->LODResources[0].PositionVertexBuffer;
     if(!VertexBuffer) return false;
     //~~~~~~~~~~~~~~~~
     
     int32 VertexCount = VertexBuffer->GetNumVertices();
      
     FTransform RV_Transform = Comp->GetComponentTransform(); 
     for(int32 Itr = 0; Itr < VertexCount; Itr++)
     {
         VertexPositions.Add(
             Comp->GetComponentLocation() + RV_Transform.TransformVector(VertexBuffer->VertexPosition(Itr))
         );
     }
     
     return true;
 }

It works great in the editor, and even on a standalone window, but when i pack it, it won't work anymore. I'v tried it as a plugin and also as a c++ class in the project, and it gave me the same results.

This is the blueprint: alt text This is in the editor: alt text And this is in a packed game: alt text

Product Version: Not Selected
Tags:
system.png (117.1 kB)
editor.jpg (125.2 kB)
packed.jpg (169.8 kB)
more ▼

asked Feb 17 '15 at 03:51 AM in C++ Programming

avatar image

Sahkan
224 10 19 24

avatar image Rama Feb 17 '15 at 06:38 PM

I can confirm this issue, I've been experiencing it since 4.3

Summary of issue: vertex positions are often jumbled or just missing in packaged game when accessed using method posted in original post and also via code below in this comment

Question For Epic

Epic is there a preferred way to access vertex data in a package game, that you recommend?

Here's the code being used that works perfect in pre-packaged game and does not work in packaged game.

It seems that using the Render Data / LOD info in packaged game does not work some reason?

 Comp->StaticMesh->RenderData->LODResources[0].PositionVertexBuffer


Is there an after-packaging better way to get the vertex position info?

Please note the rotation/translation of each vertex is scaled by the FTransform to match actor scaling and rotation.

 Comp->GetComponentLocation() + RV_Transform.TransformVector(VertexBuffer->VertexPosition(Itr))

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

2 answers: sort voted first

While searching for something similar I found a wiki page below that explains how to do this - https://wiki.unrealengine.com/Accessing_mesh_triangles_and_vertex_positions_in_build

It seems because of the way vertex data is packed in shipping builds you can't access the them through the vertex buffer on render data.

Note that I wasn't able to get the code in the wiki page to compile because of some Physx dependency issues but it's worth trying out for sure (I probably got my build.cs or includes wrong)

more ▼

answered Feb 17 '15 at 09:13 AM

avatar image

VSZ
939 24 28 55

avatar image Sahkan Feb 17 '15 at 04:25 PM

Thanks! I will take a look on it.

avatar image 황용수 Oct 05 '15 at 08:56 AM

Hi! more question...

How can i access index buffer in packed game?

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

Solution Using PhysX

Dear Community,

I've updated my BP node in my Victory BP Library plugin to use PhysX to get the vertex positions (special thanks to Vebski for pointing out that we can get accurate vert positions using PhysX in packaged games(

BP Node For You

UE4 Forum Link

https://forums.unrealengine.com/showthread.php?3851-(39)-Rama-s-Extra-Blueprint-Nodes-for-You-as-a-Plugin-No-C-Required!&p=223863&viewfull=1#post223863

C++ Code For You

Here's my C++ code that you can use to get the transformed (rotated, translated, scaled) vertex positions of any static mesh component!

Build CS

You need to include APEX and PhysX in your build.cs dependencies

 //~~~ PhysX ~~~
 #include "PhysXIncludes.h"
 #include "PhysicsPublic.h"        //For the ptou conversions
 //~~~~~~~~~~~

 //Get Transformed Vertex positions of any static mesh! -Rama
      bool UVictoryBPFunctionLibrary::GetStaticMeshVertexLocations(UStaticMeshComponent* Comp, TArray<FVector>& VertexPositions)
 {
     
     if(!Comp)                         
     {
         return false;
     }
     
     if(!Comp->IsValidLowLevel()) 
     {
         return false;
     }
     //~~~~~~~~~~~~~~~~~~~~~~~
     
     //Component Transform
     FTransform RV_Transform = Comp->GetComponentTransform(); 
     
     //Body Setup valid?
     UBodySetup* BodySetup = Comp->GetBodySetup();
     
     if(!BodySetup || !BodySetup->IsValidLowLevel())
     {
         return false;
     }  
     
     //Get the Px Mesh!
     PxTriangleMesh* TempTriMesh =BodySetup->TriMesh;
      
     if(!TempTriMesh) 
     {
         return false;
     }
     //~~~~~~~~~~~~~~~~
     
     //Number of vertices
     PxU32 NbVerts             = TempTriMesh->getNbVertices();
     
     //Vertex array
     const PxVec3* Vertices     = TempTriMesh->getVertices();
     
     //For each vertex, transform the position to match the component Transform 
     for(PxU32 v = 0; v < NbVerts; v++)
     { 
         VertexPositions.Add(RV_Transform.TransformPosition(P2UVector(Vertices[v])));
     }
     
     return true;
     
     /*
     //See this wiki for more info on getting triangles
     //        https://wiki.unrealengine.com/Accessing_mesh_triangles_and_vertex_positions_in_build
     */
 } 

Enjoy!

Rama

more ▼

answered Feb 18 '15 at 12:29 AM

avatar image

Rama
10.6k 446 343 1085

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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