A powerful Unity plugin that automates component assignment, GameObject configuration, and property setup using custom attributes and reflection. Eliminates tedious manual configuration in the Inspector.
- Features
- Installation
- Quick Start
- Core Attributes
- Usage Examples
- Editor Tools
- Requirements
- Documentation
- License
- Automatic component assignment when adding scripts
- Search in GameObject, children, parents, or entire scene
- Auto-create missing components
- Find GameObjects by tag
- Safe: never overwrites manually assigned values
- Set tags and layers automatically
- Configure sorting layers and order for 2D sprites
- Rename GameObjects programmatically
- Mark objects as static
- Apply settings recursively to children
- Configure component properties directly from code
- Works with all Unity components
- Type-safe with automatic conversion
- Multiple configurations per component
- Supports primitives, enums, and Unity types
- Unity 2021.3 or newer
- .NET Standard 2.1
- Open Unity Package Manager:
Window > Package Manager - Click the
+button in the top-left corner - Select
Add package from git URL - Enter:
https://github.com/karateka2610/UnityAutoAssign.git - Click
Add
- Download the latest release from GitHub Releases
- Extract the contents to your project's
Assetsfolder - Unity will automatically import and compile the plugin
using UnityEngine;
// Configure GameObject: tag and layer
[AutoSetup(Tag = "Player", Layer = "Character")]
public class PlayerController : MonoBehaviour
{
// Auto-assign and configure Rigidbody2D
[AutoAssign(autoCreate: true)]
[ConfigureComponent("gravityScale", 0f)]
[ConfigureComponent("constraints", RigidbodyConstraints2D.FreezeRotation)]
[SerializeField] private Rigidbody2D rb;
// Create BoxCollider2D and set as trigger
[AutoAssign(autoCreate: true)]
[ConfigureComponent("isTrigger", true)]
[SerializeField] private BoxCollider2D triggerZone;
// Find main camera in scene
[AutoAssign(searchInScene: true)]
[SerializeField] private Camera mainCamera;
void Start()
{
// Everything is ready to use!
rb.AddForce(Vector2.up * 10f);
}
}That's it! Add this script to a GameObject and all components will be created, assigned, and configured automatically.
Automatically assigns component references.
Parameters:
autoCreate- Creates the component if it doesn't existsearchInChildren- Searches in child GameObjectssearchInParent- Searches in parent GameObjectssearchInScene- Searches in the entire scenetag- Finds GameObject by tag
Configures GameObject properties. Applied to the class.
Properties:
Tag- Sets the GameObject tagLayer- Sets the GameObject layerGameObjectName- Renames the GameObjectSortingLayer- Sets sorting layer (for SpriteRenderer)SortingOrder- Sets sorting orderIsStatic- Marks GameObject as staticApplyToChildren- Applies settings to all children
Configures component properties. Can be used multiple times on the same field.
Parameters:
propertyName- Name of the property to configurevalue- Value to assign
Property:
OnlyOnCreate- Only applies when component is created (default: false)
public class Character : MonoBehaviour
{
// Assigns from same GameObject
[AutoAssign]
[SerializeField] private Rigidbody2D rb;
// Creates if missing
[AutoAssign(autoCreate: true)]
[SerializeField] private BoxCollider2D collider;
// Searches in children
[AutoAssign(searchInChildren: true)]
[SerializeField] private Animator animator;
// Searches in parents
[AutoAssign(searchInParent: true)]
[SerializeField] private Canvas canvas;
// Finds in scene
[AutoAssign(searchInScene: true)]
[SerializeField] private Camera mainCamera;
// Finds by tag
[AutoAssign(tag: "GameController")]
[SerializeField] private GameObject controller;
}// Simple tag and layer setup
[AutoSetup(Tag = "Enemy", Layer = "Enemies")]
public class Enemy : MonoBehaviour { }
// 2D sprite configuration
[AutoSetup(SortingLayer = "Characters", SortingOrder = 10)]
public class SpriteCharacter : MonoBehaviour { }
// Complete configuration
[AutoSetup(
Tag = "Player",
Layer = "Characters",
GameObjectName = "MainPlayer",
IsStatic = false
)]
public class Player : MonoBehaviour { }public class TopDownPlayer : MonoBehaviour
{
// Rigidbody2D: no gravity, no rotation
[AutoAssign(autoCreate: true)]
[ConfigureComponent("gravityScale", 0f)]
[ConfigureComponent("drag", 0f)]
[ConfigureComponent("constraints", RigidbodyConstraints2D.FreezeRotation)]
[SerializeField] private Rigidbody2D rb;
// Trigger collider with custom size
[AutoAssign(autoCreate: true)]
[ConfigureComponent("isTrigger", true)]
[ConfigureComponent("radius", 1.5f)]
[SerializeField] private CircleCollider2D detectionZone;
// AudioSource: don't play on awake, loop, 50% volume
[AutoAssign(autoCreate: true)]
[ConfigureComponent("playOnAwake", false)]
[ConfigureComponent("loop", true)]
[ConfigureComponent("volume", 0.5f)]
[SerializeField] private AudioSource bgMusic;
}using UnityEngine;
[AutoSetup(Tag = "Player", Layer = "Player")]
public class CompletePlayer : MonoBehaviour
{
[Header("Physics")]
[AutoAssign(autoCreate: true)]
[ConfigureComponent("gravityScale", 0f)]
[ConfigureComponent("drag", 0f)]
[SerializeField] private Rigidbody2D rb;
[Header("Colliders")]
[AutoAssign(autoCreate: true)]
[ConfigureComponent("isTrigger", false)]
[SerializeField] private BoxCollider2D solidCollider;
[AutoAssign(autoCreate: true)]
[ConfigureComponent("isTrigger", true)]
[ConfigureComponent("radius", 2f)]
[SerializeField] private CircleCollider2D interactionZone;
[Header("References")]
[AutoAssign(searchInScene: true)]
[SerializeField] private Camera mainCamera;
[SerializeField] private float speed = 5f;
void Update()
{
Vector2 input = new Vector2(
Input.GetAxis("Horizontal"),
Input.GetAxis("Vertical")
);
rb.velocity = input.normalized * speed;
}
}The AutoAssigner system runs automatically when:
- A script is added to a GameObject
- A script is modified or recompiled
- A script component is reset
- The Unity Editor reloads
- AutoSetup: Configures GameObject (tag, layer, sorting, etc.)
- AutoAssign: Assigns component references
- ConfigureComponent: Sets component properties
To manually re-apply all attributes:
- Select the GameObject with the script
- Right-click the script component in the Inspector
- Select Reset from the context menu
- Tools > Auto Assign > Selected GameObjects: Re-applies all attributes to selected objects
- Tools > Auto Assign > All Scene GameObjects: Re-applies all attributes to all objects in the current scene
- Unity 2021.3 or newer
- .NET Standard 2.1
- USAGE_GUIDE.md - Comprehensive usage guide with detailed examples and best practices
- CHANGELOG.md - Version history and changes
MIT License - See LICENSE.md
- Report bugs via GitHub Issues
- Feature requests welcome
- Pull requests accepted
See CHANGELOG.md for version history