S&box Wiki
Home
/
Edit Attributes and Component Properties
View
Edit
History
No Category
Developer Overview
The Project System
Publishing To Asset Party
Getting Started With Hammer
Mapping Basics
Mapping Entities
Advanced Mapping Techniques
Getting Started with Modeldoc
Animgraph & Animation
Physics
Modeldoc Nodes
Advanced Modelling
UI Basics
Styles & Stylesheets
Razor Templates
Game Menus
Materials
Built In Shaders
Shaders
Shader Reference
Sounds & Audio
Particles
Getting Started
Making Games
Input
Networking
Physics
Rendering
Editor & Tools
VR
Misc
Playing Guides
Console Commands & Variables
Dedicated Server
Log in to edit
Attributes and Component Properties
<cat>Code.Misc</cat> <title>Attributes and Component Properties</title> # Attributes Attributes in C#, generally, are metadata added to code elements such as classes, methods, or properties to assign additional semantic information that can be accessed at runtime or compile time. In S&box, we have a few attributes that do special things in the Scene Editor. Firstly, if you put `[Icon]`, `[Category]`, and `[Title]` before defining your Component class, you can give your Component an icon, category, and custom title! The `[Title]` Attribute is primarily useful if the title of your component ought to be different than the auto-set title being your Component's class name. An example of this (from the default Box Collider component) would be: ```csharp [Title("Collider - Box")] [Category("Physics")] [Icon("check_box_outline_blank")] // (etc...) public sealed class BoxCollider : Collider ``` You can [find a list of Icons on Google's Material Design Icons github.](https://github.com/google/material-design-icons/blob/master/font/MaterialIcons-Regular.codepoints). # Component Properties and You When you're creating a new Component, you may want to create variables or other objects that are exposed in the Inspector so they can be changed manually in the editor (while editing or while playing), or so you can refer to specific GameObjects or Components in the scene without getting them through code. You can do this by adding `[Property]` before defining the object. You can also add other Attributes in addition to Property, to augment the Property in the editor. For example, take a look at this Property from the CitizenAnimationHelper component: ```csharp [Property, Range( 0.5f, 1.5f ), Title( "Avatar Height Scale" )] public float Height { get; set; } = 1.0f; ``` This creates a new public float variable called Height with an auto-implemented Getter and Setter (properties need to have a Getter and Setter or they won't work) that will display in the editor with a slider that can be set between 0.5 and 1.5, with the title 'Avatar Height Scale'. <upload src="3b92d/8dc2a07c3e32451.png" size="1632" name="image.png" /> You can then drag those components into the inspector and your code will use the specific instance of that dragged-in component when executing the code that references that property! <note> [Property] members **do not** *have* to be marked as public; they can be private, protected, etc. You can also place [Property] on more than just primitive types like floats and integers. GameObjects, components like `CharacterController` and components/classes you create yourself also work. See the end of the article for some more examples.</note> # Reference ## Range As previously discussed, you can set valid ranges for Properties which will give them a slider instead of a text entry. The precision of the slider is based on what kind of variable you set-- an integer will go increments of one, a float will have decimals. ```csharp [Property, Range( 0, 6 ), Title( "How Many Apples" )] public int Apples { get; set; } = 6; ``` ## Group Groups of properties. These will appear under the same group in the inspector to make the inspector look cleaner. ```csharp [Property, Group( "Group One" ), Title( "First Thing" )] public GameObject MyFirstThing { get; set; } [Property, Group( "Group One" ), Title( "Second Thing" )] public GameObject MySecondThing { get; set; } ``` ## ToggleGroup Groups with a bool that you can toggle on/off in the inspector. To be clear- you are toggling on/off the bool, you need to do something within the code to make it respect the toggling, or the bool will just be turning on and off. ```csharp [Property, ToggleGroup( "GroupTwoToggle", Label = "Group Two (toggleable)" )] public bool GroupTwoToggle { get; set; } = false; [Property, ToggleGroup( "GroupTwoToggle" )] public GameObject CanBeToggled { get; set; } [Property, ToggleGroup( "GroupTwoToggle" ), Title( "Third Thing" )] public GameObject MyThirdThing { get; set; } [Property, ToggleGroup( "GroupTwoToggle" ), Title( "Fourth Thing" )] public GameObject MyFourthThing { get; set; } ``` ## TextArea `[TextArea]` allows you to give a `[Property]` that takes text a larger text field, if you wanted to use it for a whole paragraph or more instead of a small string. Just add it alongside an existing `[Property]` attribute. ## Enums Enums are special, each underlying enum member can have `[Icon]` and `[Description]` and `[Title]` attributes when being defined, and then when you make the Property refer to the enum type you created with those definitions, it will show up in the editor as a selector between your different enums with the fancy descriptions and titles and such for each one. Nice! ```csharp [Property] public HygieneTypes HygieneSelection; public enum HygieneTypes { [Icon( "shower" )] [Title("Take Shower")] [Description( "Take a shower" )] TakeShower, [Icon( "bathtub" )] [Title("Bathe")] [Description( "Take a bath" )] TakeBath, [Icon( "bed" )] [Title( "Back to Bed" )] [Description( "Go back to sleep instead." )] BackToSleep, } ``` Result: <upload src="3b92d/8dc2a0e539e7eda.png" size="12749" name="image.png" /> ## Lists Lists can be properties just like any other variable, and they work like you'd expect. ```csharp [Property] public List<int> ListPropertyTest { get; set; } = new List<int>(); ``` <upload src="3b92d/8dc2a1079c9f87a.png" size="4192" name="image.png" /> ## Other objects that can be used with [Property] in components Pretty much anything you'd expect to work can be used as a Property in a Component. Here are some other examples: ```csharp [Property] public Vector2 MyVector2 { get; set; } = new Vector2 { }; [Property] public Vector3 MyVector3 { get; set; } = new Vector3 { }; [Property] public Vector4 MyVector4 { get; set; } = new Vector4 { }; [Property] public Color MyColor { get; set; } = new Color(); [Property] public Rotation MyRotation { get; set; } = new Rotation(); [Property] public AudioListener MyAudioListener { get; set; } = new AudioListener(); ``` <upload src="3b92d/8dc2a11fd31f189.png" size="11472" name="image.png" />
S&box Wiki
Development
Developer Overview
6
Editor Overview
General FAQ
System Requirements
The s&box wiki
Troubleshooting
Useful Links
The Project System
4
Adding Assets
Creating a Game Project
Project Settings Window - Games
Project Types
Publishing To Asset Party
2
Uploading assets
Uploading projects
Hammer
Getting Started With Hammer
3
Getting Started With Hammer
Making Your First Map
Mapping Resources
Mapping Basics
7
Cordons
Hotspot Materials
Selection Sets
Standard Mapping Dimensions
Tool Materials
Tools Visualisation Modes
Using Entities That Require a Mesh
Mapping Entities
2
Creating a Door
Light Entities
Advanced Mapping Techniques
8
Collaborating With Prefabs and Git
Instances
Prefabs
Quixel Bridge Plugin
Tilesets
Tilesets-Advanced
Tilesets-Proxies
VIS Optimizations
Models & Animation
Getting Started with Modeldoc
7
Automatic Model Setup
Breakpieces
Creating a Model
Guide to Models
Importing Rust Weapons
LODs
ModelDoc FAQ & best practices
Animgraph & Animation
4
Animations without Animgraph
AnimEvents, AnimGraph Tags, Attachments
Animgraph
Delta Animations
Physics
3
Cloth Physics
Collisions, Physics & Surface Types
Jiggle Bones
Modeldoc Nodes
1
Custom ModelDoc nodes
Advanced Modelling
6
Bodygroups
Citizen
First Person
IKChains and Stride Retargeting
Morphs
Vertex Normals
User Interface
UI Basics
7
Custom Fonts
Embedding Websites
Enabling Pointer Events
Events and Input
Localization
UI Basics
UI with Components
Styles & Stylesheets
1
Video Backgrounds
Razor Templates
4
A Razor Overview
Aliases and SetProperty Attributes
Generic Components
Templates
Game Menus
1
Making a Custom Pause Screen
Materials & Shaders
Materials
5
Guide to Materials
Material Attributes
Material Resources
Texture Settings
Using Dynamic Expressions
Built In Shaders
2
Foliage Shader
Glass Shader
Shaders
4
Compute Shaders
Constant Buffers
Material API
Shading Model
Shader Reference
5
Anatomy of Shader Files
Getting rid of Tex2D macros
Shader Reference
Shader States
Texture Format Cheat-Sheet
Other Assets
Sounds & Audio
3
Guide to Sounds
Sound Events
Soundscapes
Particles
5
Creating animated sprites
Creating your first particle effect
Understanding Particle Editor
Using custom sprites
Using particle systems from C#
Coding
Getting Started
5
Cheat Sheet
Learning Resources
Setting up Rider
Setting up Visual Studio
Setting up Visual Studio Code
Making Games
2
Components
GameObjects
Input
4
Commands
ConVars
Input System
Speech Recognition
Networking
7
Auth Tokens
Http Requests
Lobby System
Networked Types
Networking Basics
RPCs
WebSockets
Physics
5
Collisions
Hitboxes
Joints
Traces
Triggers
Rendering
3
Render Tags
RenderHooks
Scenes
Editor & Tools
7
Creating a Tool
Custom Asset Types
Guide to Widgets
Hammer API
Hammer Gizmos
Hotload Performance
Widget Docking
VR
3
Getting Started
VR Input
VR Overlays
Misc
13
Asset Types
Attributes and Component Properties
Backend API
Cloud Assets in code
Code Accesslist
CPU Performance Profiling
DisplayInfo
FileSystem
Mounting assets at runtime
package/find
Setting Up A Navigation Mesh
Threaded Tasks
TypeLibrary
Playing
Playing Guides
3
Default Keybinds
Proton
s&box on macOS (Experimental)
Console Commands & Variables
1
Launch Arguments
Dedicated Server
1
Dedicated Servers