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"

[C++] update array or vector from inside a function

Hi, I've tried to do this for a long time, but I've got almost no success trying to not crash the engine everytime.

How to properly set inside a cpp pawn an array or vector that can be updated or changed from inside a function?

For example:

 //from pawn.h
 int array[1000]; //or int array = new int[1000];
 int* arrayPtr;
 //from pawn.cpp
 int* arrayPtr = array;
 function APawn::DoSomething(int *pointerToArray) //or int *&pointerToArray
     delete[] pointerToArray; pointerToArray = new int[1000]; //if dynamic array
     for(int i=0;i<1000;i++){   
               pointerToArray[0] = i;                    

     return pointerToArray;

I've tried a lot of times and return in various combinations crashes or weird values ( I believe memory address)

I've tried also vector the compiler says that is not anymore supported

I've tried TArray but crash the engine as well.

The examples that I've shown are perfectly compiled "stand alone" with a simple new win32 console vc++ project.

How to update an array (or show me a simple way to store integers) in c++ in UE4 way?

Product Version: UE 4.13
more ▼

asked May 07 '19 at 07:48 AM in C++ Programming

avatar image

48 2 2 8

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

1 answer: sort voted first

Personally I'd prefer to use the unreal specific classes, e.g. TArray, unless you have a specific reason for c++ arrays. Should work this way:

 // MyPawn.h
 void UpdateArray(TArray& Array);

 // MyPawn.cpp
 void AMyPawn::UpdateArray(TArray<int32>& Array) {
     // do whatever you want to with Array

     // Usage in case of a local TArray variable
     // The array can also be stored as the class member, it does not matter in this case
     TArray<int32> MyIntsArray;

more ▼

answered May 07 '19 at 08:51 AM

avatar image

435 11 18 25

avatar image thunder_nemesis May 07 '19 at 09:58 PM

Thank you very much :-) !

(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