Back to Skills

handling-tarrays

verified

ReactUMG TArray/数组属性处理指南。在传递数组给 UE 组件、使用 GridPanel 的 ColumnFill/RowFill、或遇到"不能用 JS 数组"问题时激活。必须用 UE.NewArray() 创建原生数组,包含 BuiltinFloat/String/Int 等类型常量。

View on GitHub

Marketplace

LomoMarketplace

15195999826/LomoMarketplace

Plugin

UE_ReactUMG

productivity

Repository

15195999826/LomoMarketplace

plugins/UE_ReactUMG/skills/handling-tarrays/SKILL.md

Last Verified

January 21, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/15195999826/LomoMarketplace/blob/main/plugins/UE_ReactUMG/skills/handling-tarrays/SKILL.md -a claude-code --skill handling-tarrays

Installation paths:

Claude
.claude/skills/handling-tarrays/
Powered by add-skill CLI

Instructions

# ReactUMG TArray 属性处理

## 核心规则

**TArray 属性必须使用 `UE.NewArray()`,不能直接使用 JS 数组!**

```typescript
// ❌ 错误:直接使用 JS 数组
<GridPanel ColumnFill={[1, 1, 1]} />  // Type Error!

// ✅ 正确:使用 UE.NewArray()
const columnFill = UE.NewArray(UE.BuiltinFloat);
columnFill.Add(1, 1, 1);
<GridPanel ColumnFill={columnFill} />
```

## Builtin 类型常量表

| 常量 | TypeScript 类型 | 用途 |
|------|----------------|------|
| `UE.BuiltinFloat` | `number` | **最常用** - GridPanel 的 Fill 值 |
| `UE.BuiltinInt` | `number` | 整数值 |
| `UE.BuiltinString` | `string` | 字符串 |
| `UE.BuiltinBool` | `boolean` | 布尔值 |
| `UE.BuiltinByte` | `number` | 0-255 整数 |

## 实际示例:GridPanel

```typescript
import * as UE from 'ue';

class MyPanel extends React.Component {
    // 静态创建(推荐)
    private static readonly COLUMN_FILL = (() => {
        const arr = UE.NewArray(UE.BuiltinFloat);
        arr.Add(1, 1, 1);  // 3 列等宽
        return arr;
    })();

    render() {
        return (
            <GridPanel ColumnFill={MyPanel.COLUMN_FILL}>
                {/* items */}
            </GridPanel>
        );
    }
}
```

## TArray 常用方法

```typescript
const arr = UE.NewArray(UE.BuiltinFloat);

arr.Add(1, 2, 3);        // 添加多个值
arr.Get(0);              // 获取值(不要用 arr[0]!)
arr.Set(0, 10);          // 设置值
arr.Num();               // 获取长度
arr.RemoveAt(0);         // 删除
arr.Empty();             // 清空
```

## 为什么不能用 JS 数组?

PuerTS 的 TArray 类型定义使用 `[index: number]: never` 来阻止直接下标访问,强制使用 `.Get()/.Set()` 方法,确保类型安全。

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
1277 chars