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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Set TArray Default Value UProperty

Hey guys, a quick question here. When declaring a UProperty that is TArray, how do you recommend to set the default values for said Variable inside the Header file?

I understand that the std method is by std::fill_n(array, index, value), but was curious to see how Unreal prefers data to be saved, especially within the header.

Could you provide an example of the recommended fashion? I'm particularly interested in how things like Enum Classes are stored within the declaration of the default Array Values.

Thank you very much!

Product Version: UE 4.20
more ▼

asked Dec 06 '18 at 08:49 AM in C++ Programming

avatar image

255 15 16 20

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

1 answer: sort voted first

Hey, As descibed on this question : https://answers.unrealengine.com/questions/183185/tarray-initialization.html

  TArray<int32> table = {4, 8, 15, 16, 23, 42};

internaly is us std::initializer_list for this behaviour

But i'm not aware of any way to fill an array of size X with N as default value in the header

more ▼

answered Dec 06 '18 at 03:32 PM

avatar image

1.5k 14 18 32

avatar image me4dinosaur Dec 06 '18 at 09:58 PM

Okay, this way I also knew.

I see. Any clues on how it would work?

avatar image Spidermined Dec 07 '18 at 03:12 AM

The Coding Standard also explains the advantages and downsides to initializing in the header and right above that it explains Strongly Typed Enums.

avatar image me4dinosaur Dec 07 '18 at 07:58 AM

I've also looked into this already. It does not state anywhere for TArray Initialization.

(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