ChainSafe / ChainSafe/open-creator-rails.unity
Editor Warning for Duplicate Asset (AssetId + RegistryAddress) in Scene
- Dominant language
- C#
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
**What**
Add a custom Unity Editor script for the `Asset` MonoBehaviour (`Asset.cs`) that detects when two or more `Asset` components in the scene share the same `AssetId` + `RegistryAddress` pair and displays an inline Inspector warning:
> _"Asset already exists: another Asset in the scene has the same Asset Id and Registry Address."_
The existing `HierarchyChangeHandler.cs` (in `Editor/`) already listens to `EditorApplication.hierarchyChanged` and iterates all scene `Asset` instances — the duplicate detection fits naturally alongside it in a companion `AssetEditor` custom Inspector.
**Why**
The `OpenCreatorRailsService` deduplicates assets at runtime by `(AssetId, RegistryAddress)` pair (see `TryAddAsset`), so two components with the same pair will silently collapse to one at runtime. Without an Editor-time warning, a developer setting up their scene has no indication that one of their `Asset` components will be ignored, which leads to confusing runtime behaviour.
**How**
1. Create `io.chainsafe.open-creator-rails/Editor/AssetEditor.cs` with `[CustomEditor(typeof(Asset))]`
2. In `OnInspectorGUI`:
- Call `DrawDefaultInspector()` to preserve the standard serialized field layout
- Find all scene `Asset` instances via `Object.FindObjectsByType(FindObjectsInactive.Exclude, FindObjectsSortMode.None)`
- Check whether any other instance (not `this`) has the same `AssetId` **and** `RegistryAddress`
- If a duplicate is found, draw an `EditorGUILayout.HelpBox` with `MessageType.Warning`:
```
Asset already exists: another Asset in the scene has the same Asset Id and Registry Address.
```
3. Subscribe to `EditorApplication.hierarchyChanged` in the editor class (or reuse the existing handler) to call `Repaint()` on the active editor so the warning appears and clears reactively without the developer needing to click away and back
**Acceptance Criteria**
- [ ] Two `Asset` components with identical `AssetId` + `RegistryAddress` → both show the inline `HelpBox` warning in their Inspector
- [ ] Editing a field on one to make the pair unique → warning clears immediately without requiring focus change
- [ ] A single `Asset` component, or two with different pairs, shows no warning
- [ ] Warning is displayed inline in the Inspector via `HelpBox` (not only in the console)
- [ ] Default Inspector field layout is unchanged — `DrawDefaultInspector()` is still called
**Estimation**
**Dependencies**
None.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.