Your First SoapKit System 🚀
Ready to experience the magic of decoupled game architecture? In the next 10 minutes, you'll build a complete health system that would make any senior developer proud.
Step 1: Installation
From Unity Asset Store:
- Search for "SoapKit"
- Download and import
- Let Unity refresh - grab some coffee ☕
Verify Everything Works:
- Check
Tools > SoapKit > Debug Windowexists - Right-click in Project:
Create > SoapKitshould be there
If you see these menus, you're golden! 🎉
Step 2: Create Your First Assets
Here's where SoapKit shines. Instead of hard-coding values in scripts, we create ScriptableObject assets that multiple systems can share.
Create a Player Health Variable:
- Right-click in Project →
Create > SoapKit > Variables > Int Variable - Name it
Player Health - In the Inspector, set Value to
100
Create Health Events:
Create > SoapKit > Events > Unit Event→ name itOn Player DiedCreate > SoapKit > Events > Int Event→ name itOn Health Changed
Your project now has shared data (the health variable) and communication channels (the events). Any script can reference these assets!
Step 3: Build the Health System
Time for the fun part. Create a new script called HealthSystem.cs:
using UnityEngine;
using FarmGrowthToolkit.Soap;
public class HealthSystem : MonoBehaviour
{
[Header("📊 Health Data")]
[SerializeField] IntVariable playerHealth;
[Header("📡 Events")]
[SerializeField] UnitGameEvent onPlayerDied;
[SerializeField] IntGameEvent onHealthChanged;
void Start()
{
// Listen for health changes
playerHealth.OnValueChanged += HandleHealthChanged;
// Set starting health
playerHealth.SetValue(100);
}
public void TakeDamage(int damage)
{
playerHealth.Subtract(damage); // SoapKit's built-in math!
}
public void Heal(int amount)
{
playerHealth.Add(amount);
// Cap at 100
if (playerHealth.Value > 100)
playerHealth.SetValue(100);
}
void HandleHealthChanged(int newHealth)
{
onHealthChanged.Raise(newHealth); // Tell everyone health changed
if (newHealth <= 0)
onPlayerDied.Raise(); // Tell everyone player died
Debug.Log($"Player health: {newHealth}");
}
void OnDestroy()
{
// Always clean up event subscriptions!
playerHealth.OnValueChanged -= HandleHealthChanged;
}
}
Look how clean that is! No direct references to UI, audio, or any other systems. The health system just manages health and broadcasts what happened.
Step 4: Add a UI System
Now let's create a UI that reacts to health changes automatically. Create HealthUI.cs:
using UnityEngine;
using UnityEngine.UI;
using FarmGrowthToolkit.Soap;
public class HealthUI : MonoBehaviour
{
[Header("🎨 UI Components")]
[SerializeField] Slider healthBar;
[SerializeField] Text healthText;
[Header("📡 Events to Listen To")]
[SerializeField] IntGameEvent onHealthChanged;
[SerializeField] UnitGameEvent onPlayerDied;
void OnEnable()
{
// Subscribe to events - UI reacts automatically!
onHealthChanged.AddListener(UpdateHealthDisplay);
onPlayerDied.AddListener(ShowGameOver);
}
void OnDisable()
{
// Always clean up
onHealthChanged.RemoveListener(UpdateHealthDisplay);
onPlayerDied.RemoveListener(ShowGameOver);
}
void UpdateHealthDisplay(int newHealth)
{
healthBar.value = newHealth;
healthText.text = $"Health: {newHealth}";
}
void ShowGameOver()
{
healthText.text = "GAME OVER";
healthText.color = Color.red;
}
}
Notice something cool? The UI system knows nothing about the health system, yet they work together perfectly through events!
Step 5: Wire Everything Up
Set up the Scene:
- Create an empty GameObject called "Health Manager"
- Add your
HealthSystemscript - Drag your SoapKit assets into the script fields
Create Simple UI:
- Create a Canvas (
UI > Canvas) - Add a Slider (
UI > Slider) - set Max Value to 100 - Add a Text element (
UI > Text) - Create empty GameObject called "Health UI"
- Add the
HealthUIscript and connect the UI references
Connect the Events:
- Drag the same event assets to both the Health System and Health UI
- This is the magic - shared events connect your systems!
Step 6: Test It Out!
Quick Testing with Keyboard: Add this simple script for testing:
using UnityEngine;
public class HealthTester : MonoBehaviour
{
[SerializeField] HealthSystem healthSystem;
void Update()
{
if (Input.GetKeyDown(KeyCode.X))
healthSystem.TakeDamage(25); // Press X to take damage
if (Input.GetKeyDown(KeyCode.Z))
healthSystem.Heal(20); // Press Z to heal
}
}
Or Use SoapKit's Debug Window:
- Open
Tools > SoapKit > Debug Window - Find your variables and events
- Watch values change in real-time
- Click events to test them instantly
Hit Play and press X a few times. Watch the magic happen! ✨
🎉 You Did It!
In just a few minutes, you built a professional-grade system architecture! Here's what makes this special:
✅ Zero Dependencies - Health system has no idea UI exists
✅ Automatic Updates - UI responds instantly when health changes
✅ Designer Friendly - Anyone can tweak values in the Inspector
✅ Easily Testable - Each system works in isolation
✅ Infinitely Expandable - Add new systems without changing existing code
The "Aha!" Moment 💡
Here's what just clicked: systems don't talk to each other directly. They talk to shared data (Variables) and broadcast notifications (Events). It's like having a bulletin board that everyone can read and post to!
What's Next?
Experiment Right Now (5 minutes):
Try adding an audio system that plays a sound when health changes:
public class HealthAudio : MonoBehaviour
{
[SerializeField] IntGameEvent onHealthChanged;
[SerializeField] AudioSource audioSource;
void OnEnable() {
onHealthChanged.AddListener(PlayHealthSound);
}
void PlayHealthSound(int health) {
audioSource.Play(); // Plays automatically when health changes!
}
}
No changes to existing code needed! Just subscribe to the same events. 🎵
Level Up Your Skills:
- 🎯 Master Events & Variables - Deep dive into the core concepts
- 🛠️ Build Real Systems - Complex examples with best practices
- 🔧 Debug Like a Pro - Professional debugging tools
Join the Community:
- Discord - Get help and share your creations
- GitHub - Contribute and request features
- Asset Store - Leave a review if SoapKit helped you!
💭 What Just Happened?
You experienced the core philosophy of SoapKit: systems that work together without being tangled together. This isn't just cleaner code - it's a completely different way of thinking about game architecture.
Traditional approach: "How do I make the UI know about the health system?"
SoapKit approach: "How do I let any interested system know when health changes?"
The difference is profound. With SoapKit, you're not building dependencies - you're building a communication network where systems can join and leave conversations naturally.
Welcome to professional game development! 🎮✨