JetBrains / JetBrains/resharper-unity
Set default asset references for script asset
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 142
- PR merge metrics
- No merged PRs in 30d
Description
Default values for a script component are set by field initialisers for primitive types (e.g. `float velocity = 1.5f;`. It's not possible to set default asset references in code. There isn't a value to set for e.g. `GameObject enemy = ???;`
These default references are shown as Import Settings in the Inspector window for a script asset, when selected in the Project view. Here it's possible to pick asset references, although the values must come from the Project view, rather than the Hierarchy view.
The default references are serialised to the script's `.cs.meta` file. E.g.:
```
fileFormatVersion: 2
guid: 18ff8bad9ca6f4f29ab5526c0893ae7b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- lightSource: {instanceID: 0}
- something: {fileID: 100000, guid: 87b70b92195974d9dacc05039e07b8cf, type: 3}
- component: {fileID: 400000, guid: 87b70b92195974d9dacc05039e07b8cf, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
```
Investigate how Rider can make use of this.
* Should Rider show this default reference as a Code Vision link?
* Can Rider choose the default reference from within the editor?
* Can Rider invoke `Reset` on serialised objects? If the defaults are edited in code (or the default references are updated in the Import Settings), then using `Reset` will reset a serialised instance to these values. Can Rider use the protocol to reset all instances, or rewrite the scene to update serialised data?
See [this forum post for more details](https://forum.unity.com/threads/setting-variable-default-values-in-editor.391821/#post-2554514).
Contributor guide
Research direction
Start with Unity's Inspector Import Settings and the serialized defaultReferences entries in the script's .cs.meta file. Investigate whether Rider can expose these references through Code Vision, edit them in the editor, or invoke Reset for serialized instances. Done means identifying a supported workflow and defining the required Rider behavior for each question.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, unity
- Domain
- game-dev, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100