UnityQuery is a small, lightweight C# library designed to increase productivity with Unity3D.
Each and every one of us has written these small utility and extension methods we're using and re-writing over and over again with each new project. UnityQuery aims to collect the most general, versatile and helpful of these code snippets for re-use, and is inspired by recent work at the Slash Framework and by LINQ to GameObject by Yoshifumi Kawai.
If you're missing any of your personal favorites, we'd love to see it - please refer to the Contributing file!
- Hierarchy queries (e.g. GetChildren, GetDescendants, OnLayer, IsAncestor, GetRoot, ...)
- Hierarchy manipulation (e.g. DestroyChildren)
- Component-wise vector swizzling (e.g. v.XZ)
- Changing single vector or color components while preserving immutability
- Picking (e.g. object at mouse position)
- Collection extensions (e.g. ContainsAll, GetValueOrDefault, IsNullOrEmpty, SequenceToString)
- Logs with timestamps and object names
You can either
- download the latest Unity package, or
- checkout the repository (requires Unity Test Tools)
Later releases will be available at the Asset Store as well.
Just import the UnityQuery
namespace and you're good to go!
using UnityQuery;
Right now, all of the UnityQuery methods are implemented as extension methods.
Vector3 u = new Vector3(1, 2, 3);
Vector2 v = u.XY();
That means, you can use all of them as syntatic sugar without having to recall where they're located.
var o = Camera.main.PickObject();
Note there's also a Cheat Sheet available for you.
We know that using a library like UnityQuery in production requires you to be completely sure about stability and compatibility. Thus, new releases of UnityQuery are created using Semantic Versioning. In short:
- Version numbers are specified as MAJOR.MINOR.PATCH.
- MAJOR version increases indicate incompatible changes with respect to the public UnityQuery API.
- MINOR version increases indicate new functionality that are backwards-compatible.
- PATCH version increases indicate backwards-compatible bug fixes.
We are sorry that you've experienced issues or are missing a feature! After verifying that you are using the latest version of UnityQuery and having checked whether a similar issue has already been reported, feel free to open a new issue. In order to help us resolving your problem as fast as possible, please include the following details in your report:
- Steps to reproduce
- What happened?
- What did you expect to happen?
After being able to reproduce the issue, we'll look into fixing it immediately.
(in no particular order)
- Nick Prühs (Maintainer)
- Christian Oeing
- Björn von der Osten
- Patrick Henschel
- Michael Kluge
UnityQuery is released under the MIT license.