# Unity Quest System
A flexible and extensible quest system for Unity games that supports multiple quest types, random generation, and reward distribution.
## π Table of Contents
- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Components Overview](#components-overview)
- [Usage Examples](#usage-examples)
- [Customization](#customization)
- [Best Practices](#best-practices)
- [Troubleshooting](#troubleshooting)
## β¨ Features
- Multiple quest types (Collection, Elimination, Exploration, Escort, Delivery)
- Random quest generation with customizable parameters
- Dynamic reward system
- Quest tracking and progress management
- Event-driven architecture
- Player level scaling
- Location-based objectives
- Flexible reward system
## π Installation
1. Create a new folder in your Unity project's Assets folder named `QuestSystem`
2. Copy the following scripts into the folder:
- Quest.cs
- QuestGenerator.cs
- QuestTrigger.cs
- QuestManager.cs
- ItemReward.cs
## πββοΈ Quick Start
### Basic Setup
1. Create a new empty GameObject in your scene and name it "QuestSystem"
```csharp
GameObject questSystem = new GameObject("QuestSystem");-
Add the required components:
- Add QuestManager component
- Add QuestGenerator component
-
Configure the QuestGenerator in the Inspector:
- Add quest titles
- Add quest descriptions
- Configure possible rewards
- Set experience and gold ranges
- Create an NPC or interaction point
- Add the QuestTrigger component
- Configure the trigger settings:
// In the Inspector
Interaction Range: 3
Interaction Key: E
Quest Available Indicator: [Assign your indicator prefab]Controls the overall quest system:
// Get reference to Quest Manager
QuestManager questManager = FindObjectOfType<QuestManager>();
// Add a new quest
Quest newQuest = questManager.GenerateNewQuest();
questManager.AddNewQuest(newQuest);
// Complete a quest
questManager.CompleteQuest("questId");
// Update quest progress
questManager.UpdateQuestProgress("questId", 0, 1);Generates random quests:
// Configure in Inspector
[SerializeField] private List<string> questTitles;
[SerializeField] private List<string> questDescriptions;
[SerializeField] private List<ItemReward> possibleRewards;Handles player interactions:
// Events you can subscribe to
onQuestOffered.AddListener(YourMethod);
onQuestAccepted.AddListener(YourMethod);
onPlayerEnterRange.AddListener(YourMethod);
onPlayerExitRange.AddListener(YourMethod);// 1. Create an NPC GameObject
GameObject npc = GameObject.CreatePrimitive(PrimitiveType.Capsule);
npc.name = "QuestGiver";
// 2. Add QuestTrigger component
QuestTrigger trigger = npc.AddComponent<QuestTrigger>();
// 3. Add Collider (if not present)
SphereCollider collider = npc.AddComponent<SphereCollider>();
collider.isTrigger = true;
collider.radius = 3f;void Start()
{
QuestManager questManager = FindObjectOfType<QuestManager>();
questManager.onQuestAdded.AddListener(OnQuestAdded);
questManager.onQuestCompleted.AddListener(OnQuestCompleted);
questManager.onQuestFailed.AddListener(OnQuestFailed);
}
void OnQuestAdded(Quest quest)
{
Debug.Log($"New quest added: {quest.title}");
// Update UI or other game systems
}- Add new type to QuestType enum:
public enum QuestType
{
Collection,
Elimination,
Exploration,
Escort,
Delivery,
YourNewType
}- Add handling in QuestGenerator:
case QuestType.YourNewType:
objectives.Add(new QuestObjective
{
description = "Your new objective",
requiredAmount = Random.Range(1, 5),
currentAmount = 0,
isCompleted = false
});
break;// Create new reward types
[System.Serializable]
public class CustomReward : ItemReward
{
public float specialBonus;
public string uniqueEffect;
}-
Quest Design
- Keep objectives clear and measurable
- Balance rewards with quest difficulty
- Use meaningful descriptions
- Test quest completion conditions thoroughly
-
Performance
- Don't overuse quest triggers in a single scene
- Clean up completed quests periodically
- Use object pooling for quest markers
- Implement proper save/load systems
-
UI Integration
- Create clear quest log interface
- Show quest markers on minimap
- Provide clear feedback for progress
- Include quest tracking options
-
Quests not triggering
- Check if QuestSystem GameObject is in the scene
- Verify QuestTrigger collider settings
- Ensure player has "Player" tag
-
Rewards not distributing
- Check QuestManager reference
- Verify reward values in Inspector
- Debug reward distribution method
-
Quest progress not updating
- Verify quest ID matches
- Check objective index
- Ensure progress values are correct
// Add to QuestManager
[SerializeField] private bool debugMode = false;
private void DebugLog(string message)
{
if (debugMode)
Debug.Log($"[Quest System]: {message}");
}To update the system:
- Backup your current quest data
- Update script files
- Test in a development scene
- Check for any breaking changes
- Update existing quests if needed
- Create UI prefabs for quest notifications
- Design quest marker icons
- Implement sound effects for quest events
- Add particle effects for quest completion
Feel free to:
- Report bugs
- Suggest improvements
- Add new features
- Share your customizations
This quest system is available under the MIT License. Feel free to use and modify it in your projects.
This README provides a comprehensive guide for implementing and using the quest system. Would you like me to expand on any particular section or add more specific examples?