Description
Resets the array to Number elements, every one a copy of Element. Equivalent to calling Empty(Number) then adding Number copies of Element.
Caveats & Gotchas
- • Calls Empty first, which destroys all existing elements and resets the count to zero before refilling. This means Init always discards previous contents — it is not an append or a partial fill.
- • Each element is copy-constructed from Element (via Add), so the element type must be copy-constructible. The copy happens Number times; avoid using large structs as Element if Number is large, as the copies are sequential.
Signature
void Init(const ElementType& Element, SizeType Number) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Element | const ElementType& | The value to copy into every slot. | — |
| Number | SizeType | The number of elements the array should contain after the call. | — |
Return Type
void Example
Initialise a health pool to full C++
TArray<float> HealthPool;
HealthPool.Init(100.f, NumCharacters); // all NumCharacters entries set to 100.0 Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?