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"

Get pointer to data from FVector (like std::vector.data())

In std::vector you have vector.data() function that returns a type* pointer to the start of the vector.

You can use that in combination with vector.size() for functions requiring dynamic arrays like:

 void function(const float* data, int arraySize)

so you can call:

 function(vector.data(), vector.size())

Is there any way I can do this with FVector, without having to convert FVector to std::vector and back again?

Product Version: UE 4.16
Tags:
more ▼

asked Jun 02 '17 at 11:07 AM in C++ Programming

avatar image

virtual_method
8 1 6 6

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

3 answers: sort voted first

TArray (which analogous to std::vector) has a GetData method.

So, it would be

 function(MyArray.GetData(), MyArray.Num());
more ▼

answered Jun 02 '17 at 02:39 PM

avatar image

ExtraLifeMatt
1.6k 34 14 48

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

In C++ you can.... cast.

 FVector myVector(cool values);
 float *pFloat = (float*)&myVector;
 int floatCount = sizeof(FVector) / sizeof(float);

Not the most elegant thing to do in general but probably fairly safe here.

I believe C++ defines that elements within a single private/protected/public block will be in order. As FVector doesn't have virtual functions you don't have to worry about a pointer (typically at the start of an object, but doesn't have to be).

 struct FVector 
 {
 public:
 
     /** Vector's X component. */
     float X;
 
     /** Vector's Y component. */
     float Y;
 
     /** Vector's Z component. */
     float Z;

Given that X is the first element you could also go with:

float *pFloat = &myVector.X;

pFloat[1] will be Y, [2] will be Z.

more ▼

answered Jun 03 '17 at 11:00 PM

avatar image

theonecalledtom
1.3k 61 68 271

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

If you want the same functionality as an std::vector you want to be using a TArray. An FVector is a 3D point used for math (X, Y, Z).

TArray has a .GetData() as well as a .Num()

more ▼

answered Jan 16 '18 at 08:09 PM

avatar image

Rynold
56 8 9 15

(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