Search Result Lite & Pro – Simplify Your Code, Avoid Runtime Errors!
Eliminate common coding headaches and streamline your Unity development with Search Result Lite & Pro. This powerful asset enhances your projects by providing safe access methods, reducing runtime errors, and improving code reliability. Whether you’re working on small projects or large-scale systems, Search Result is your go-to tool for safe and efficient data handling.
Try the Lite Version here : https://assetstore.unity.com/packages/tools/utilities/search-result-lite-302098
Buy the Pro Version here : https://assetstore.unity.com/packages/tools/utilities/search-result-pro-302123
Core Features (Lite & Pro):
- Safe Lists & Arrays Access: Never worry about out-of-bounds errors—automatically handle invalid indices.
- Safe GameObject Access: Access objects safely, even if they’re destroyed mid-gameplay.
Upcoming Features (Lite):
- Default Values: Quickly return a default value in case of errors, which can be used safely.
- Basic Dictionary Access: Quickly and safely access Dictionary of common data types without having to check for index, keys, values or null references.
- Automated Bug Reporting: Streamline QA with auto-generated logs for testing and issue tracking.
Pro-Exclusive Features:
- Operator Overloading Support: We have added some quality of life improvements to enhance the readability of your code.
- Full Source Code Access: Customize the asset to suit your project’s unique needs.
- Priority Support: Get faster assistance and updates tailored to your needs.
- Safe Custom Class Access: Eliminate null reference errors in your data models and game logic.
- Default Checks: Define fallback rules to ensure predictable behavior in edge cases.
Upcoming Features (Pro):
- Custom Debugging Tools: An editor window to visualize and monitor errors in real-time.
- Automated Bug Reporting: Streamline QA with auto-generated logs for testing and issue tracking.
Key Use Cases in Unity Projects
1. Safe Data Access
- Lists and Arrays: The
SafeGet
extension methods for lists and arrays help retrieve elements without worrying about null references, out-of-bounds errors, or runtime crashes. For example:
var myList = new List<int> { 1, 2, 3 };
var result = myList.SafeGet(5);
if (result.isError)
Debug.LogError(result.errorMessage);
else
Debug.Log(result.result);
- This is especially useful when working with dynamically sized collections, such as inventories, object pools, or runtime-generated datasets.
2. Error Messaging with Context
- The use of
[CallerMemberName]
and[CallerLineNumber]
attributes inSafeGet
methods allows developers to quickly identify where an error occurred in the code. This makes debugging faster and more intuitive.- Example: “Index is outside bounds of array at
MyMethod
at line 42.”
- Example: “Index is outside bounds of array at
3. GameObject Modifications
- The
SafeModify
method provides a structured way to modify GameObjects while handling potential exceptions gracefully. This can be used for tasks such as:- Adding or removing components.
- Updating properties (e.g.,
transform.position
,Renderer.material
). - Custom logic based on runtime checks.Example:
GameObject myObject = GameObject.Find("Player");
myObject.SafeModify(obj =>
{
obj.transform.position = new Vector3(0, 1, 0);
}, error => Debug.LogError(error));
4. Preventing Common Errors in Unity
- Null Reference Exceptions: These extensions ensure that null references are caught and handled before they cause crashes.
- Index Out-of-Bounds: Improves safety when accessing indices, reducing runtime errors caused by invalid inputs.
- Runtime Exception Handling: Provides a unified approach to catching exceptions across different object types, ensuring smoother gameplay and debugging.
5. Customization and Extendability
- By providing a generic structure (
SearchResult<T>
), this framework allows developers to easily extend functionality to other data types, like custom structs or objects. - For instance, a custom extension method could be created for retrieving specific components from a list of GameObjects:
public static SearchResult<T> SafeGetComponent<T>(this GameObject obj) where T : Component
{
if (obj == null)
return SearchResult<T>.Error("GameObject is null");
T component = obj.GetComponent<T>();
return component != null
? SearchResult<T>.Success(component)
: SearchResult<T>.Error($"Component {typeof(T)} not found on GameObject");
}
6. Collaborative Development and Modular Code
- Enables safer code when multiple developers are working on a project. The clear separation of error handling (e.g., using
onError
callbacks) and functional logic (e.g.,onSuccess
) helps streamline debugging and maintenance. - Example:
myGameObject.SafeModify(obj =>
{
obj.AddComponent<Rigidbody>();
}, error => Debug.LogError($"Failed to modify GameObject: {error}"));
7. Error Logging for QA and Bug Tracking
- With precise error messages and contextual information, QA testers can pinpoint issues and provide detailed reports. Developers can also integrate these error messages with bug tracking tools.
Benefits for Unity Developers
- Reduced Debugging Time: Eliminates the need to manually write boilerplate error checks for common operations.
- Improved Stability: Prevents crashes caused by common mistakes like accessing null objects or out-of-range indices.
- Enhanced Collaboration: Clear error reporting ensures team members can quickly identify and resolve issues.
- Code Reusability: The generic approach and extensible design ensure that these utilities can be reused across various projects and scenarios.
By integrating these utilities into a Unity project, developers can focus on building features and gameplay mechanics rather than worrying about runtime stability.
Use Case: Safe Inventory Management in a Game (Using PRO version)
Scenario
You are building an inventory system for an RPG game. Players can access their inventory to view items or equip them during gameplay. However, there may be cases where the player tries to access an item that doesn’t exist or the inventory is empty. The SearchResultPro
class ensures these operations are handled gracefully without breaking the game flow.
Code Example:
using UnityEngine;
using System.Collections.Generic;
using RedstoneinventeGameStudio.Pro.Utilities;
public class InventoryManager : MonoBehaviour
{
private List<string> inventoryItems;
void Awake()
{
// Add a default check to quickly check results before returning
AddDefaultCheck();
}
void Start()
{
TestSafeGet(1); // Null references are also handled
// Initialize inventory with some items
inventoryItems = new List<string> { "Sword", "Shield", "Potion" };
// Use SafeGet to access an item safely
TestSafeGet(1); // Valid index
TestSafeGet(-1); // Invalid index
TestSafeGet(10); // Out of bounds index
}
void TestSafeGet(int index)
{
// Using SafeGet with inline success and error handling
inventoryItems.SafeGet(index,
onSuccess: item => Debug.Log($"Successfully retrieved item: {item}"),
onError: error => Debug.LogError($"Failed to retrieve item: {error}")
);
}
public void EquipItem(int index)
{
// Use SafeGet to retrieve an item before equipping
SearchResultPro<string> result = inventoryItems.SafeGet(index);
if (result)
{
Debug.Log($"Equipping item: {result.result}");
// Equip logic here...
}
else
{
Debug.LogError($"Cannot equip item: {result.errorMessage}");
}
}
public void AddDefaultCheck()
{
// Set a default predicate to prevent equipping empty or invalid item names
SearchResultPro<string>.SetDefaultCheck(item => !string.IsNullOrEmpty(item));
}
}
Features Demonstrated:
- Safe Retrieval:
UseSafeGet
to avoid runtime errors when accessing inventory items, especially when indices are out of range. - Error Handling with Callbacks:
InlineonSuccess
andonError
callbacks provide immediate and readable handling of success or failure scenarios. - Custom Default Checks:
Ensure retrieved items meet specific criteria by adding adefaultCheck
. For example, prevent equipping items with invalid names. - Implicit Conversion:
Simplifies error checking with implicit conversion (if (result)
), making the code cleaner and easier to understand. - Pro Extensions:
The extended functionality adds safety and clarity when working with collections like arrays and lists, reducing potential errors and debugging time.
Example Output:
List is empty at TestSafeGet at line 17
Successfully retrieved item: Shield
Failed to retrieve item: Index is outside bounds of array at TestSafeGet at line 24
Failed to retrieve item: Index is outside bounds of array at TestSafeGet at line 25
Equipping item: Sword
Cannot equip item: Index is outside bounds of array
This use case highlights how the Pro Version enhances development by providing robust, reusable, and error-resilient data handling tools. It reduces the need for repetitive null checks, making your codebase more efficient and readable.
Why Choose Search Result Lite & Pro?
This asset solves real-world problems faced by Unity developers, making your projects safer, smoother, and easier to manage. The Lite version is perfect for those looking to try safe access methods, while Pro unlocks advanced tools and customization for professional-grade projects.
Take the hassle out of debugging and let Search Result Lite & Pro do the heavy lifting for you.
Get started with Lite for free or upgrade to Pro to unlock the full potential of your workflow!
Try the Lite Version here : https://assetstore.unity.com/packages/tools/utilities/search-result-lite-302098
Buy the Pro Version here : https://assetstore.unity.com/packages/tools/utilities/search-result-pro-302123
Items marked with a (*) means it will be added in the future.