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"

Convert std::vector to TArray

Hey all,

So I'm stumped. I am working with a third-party library that outputs a std::vector. This vector is to be converted into a TArray for use in the CreateMeshSection_LinearColor element of the procedural mesh generation system. I have yet to find an effective method to convert this data, because converting from vectors to TArrays is not terribly clean, and the transition from float to fvector is not common. This may be an impossible task (at which point I may have to edit the third party library), however I thought I would ask to see if this was possible. Thanks!

Cheers, Gazebo

Product Version: UE 4.15
more ▼

asked Apr 02 '17 at 03:33 AM in C++ Programming

avatar image

3 1 3 5

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

2 answers: sort voted first

Well you wont find a premade method for that, but it can be very simply don manually like this for example:

 std::vector<float> vec;
 TArray<float> arr;
 for(int i=0; i< vec.size(); i++){
   arr[i] = vec[i];

You can of course also convert any types in that loop if you need to.

more ▼

answered Apr 02 '17 at 06:30 AM

avatar image

1.3k 46 29 59

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

The other answer doing it using a loop is absolutely correct, but there is also a more compact solution using the raw version of Tarray::Append (API doc)

Note that this does only work for std::vector and C arrays, because the memory used internally has to be in continuous order, which is only guaranteed by std::vector. Don't use it with std::list, std::deque or any other std container.

 std::vector<float> vec = {0.f, 1.5f, 4.f};
 TArray<float> arr;
 arr.Append(&vec[0], vec.size());

Or using an C array

 float arr[] = {0.f, 1.5f, 4.f};
 TArray<float> arr;
 arr.Append(arr, 3);

more ▼

answered Apr 02 '17 at 08:51 AM

avatar image

581 14 12 37

(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