All-in-One Solution for Indie Game Development · Empowering Indie Developers' Dreams
Documentation · Quick Start · QQ Group: 467608841 / 233840761
- Project Overview
- Key Features
- Quick Start
- Usage Examples
- Entity Lifecycle
- Architecture
- Documentation & Resources
- Community & Support
- Changelog
- License
The Entity Component provides a complete entity management system for Unity games. It handles entity lifecycle (show, hide, recycle), grouping, parent-child hierarchy, and integrates with the asset system for async resource loading and object pools for instance reuse.
Built on top of the GameFrameX framework, it uses UniTask for async operations and provides a Manager-Component-Helper layered architecture.
- Async Entity Spawning — Load and instantiate entities asynchronously via UniTask, with progress and dependency callbacks
- Entity Grouping — Organize entities into groups with individual object pool settings (capacity, expire time, auto-release interval)
- Parent-Child Hierarchy — Attach/detach child entities with automatic Transform parenting
- Object Pool Integration — Reuse entity instances through object pools for memory efficiency
- Event-Driven Lifecycle — Subscribe to Show/Hide/Update/DependencyAsset events for reactive workflows
- EntityLogic Pattern — Implement business logic by subclassing
EntityLogicwith OnInit/OnShow/OnHide/OnUpdate lifecycle methods - Instance Management — Lock entity instances or adjust priority for pool eviction control
Choose one of the following methods:
-
Edit your Unity project's
Packages/manifest.jsonand add thescopedRegistriessection:{ "scopedRegistries": [ { "name": "GameFrameX", "url": "https://gameframex.upm.alianblank.uk", "scopes": [ "com.gameframex" ] } ], "dependencies": { "com.gameframex.unity.entity": "2.4.3" } }scopescontrols which packages are resolved through this registry. Only packages whose names start withcom.gameframexwill be fetched from it. -
Add to
manifest.jsondependencies:{ "com.gameframex.unity.entity": "https://github.com/gameframex/com.gameframex.unity.entity.git" } -
Use Package Manager in Unity with Git URL:
https://github.com/gameframex/com.gameframex.unity.entity.git -
Clone the repository into your Unity project's
Packagesdirectory. It will be loaded automatically.
Create a subclass of EntityLogic to implement your entity's behavior:
using GameFrameX.Entity.Runtime;
using UnityEngine;
public class PlayerEntity : EntityLogic
{
protected internal override void OnInit(object userData)
{
base.OnInit(userData);
// Initialize component references, etc.
}
protected internal override void OnShow(object userData)
{
base.OnShow(userData);
// Called when the entity is shown
}
protected internal override void OnHide(bool isShutdown, object userData)
{
base.OnHide(isShutdown, userData);
// Called when the entity is hidden
}
protected internal override void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
base.OnUpdate(elapseSeconds, realElapseSeconds);
// Per-frame update logic
}
}Use EntityComponent to asynchronously spawn an entity:
// Get the EntityComponent
var entityComponent = GameEntry.GetComponent<EntityComponent>();
// Show entity asynchronously
IEntity entity = await entityComponent.ShowEntityAsync<PlayerEntity>(
entityId: 1,
entityAssetName: "Assets/Prefabs/Player.prefab",
entityGroupName: "PlayerGroup"
);// Hide by entity ID
entityComponent.HideEntity(1);
// Hide by entity reference
entityComponent.HideEntity(entity);
// Hide all loaded entities
entityComponent.HideAllLoadedEntities();Attach child entities to form parent-child relationships:
// Attach child to parent
entityComponent.AttachEntity(childEntity, parentEntity);
// Attach with a specific Transform path
entityComponent.AttachEntity(childEntity, parentEntity, "Weapon/RightHand");
// Detach child
entityComponent.DetachEntity(childEntity);
// Detach all children of a parent
entityComponent.DetachChildEntities(parentEntity);entityComponent.ShowEntitySuccess += (sender, e) =>
{
Debug.Log($"Entity shown: {e.Entity.Id}");
};
entityComponent.ShowEntityFailure += (sender, e) =>
{
Debug.LogError($"Entity failed: {e.ErrorMessage}");
};
entityComponent.HideEntityComplete += (sender, e) =>
{
Debug.Log($"Entity hidden: {e.EntityId}");
};| Stage | Method | Description |
|---|---|---|
| Init | OnInit(object userData) |
First-time initialization, cache references |
| Show | OnShow(object userData) |
Entity becomes visible and active |
| Update | OnUpdate(float, float) |
Per-frame update when entity is shown |
| Hide | OnHide(bool isShutdown, object userData) |
Entity is hidden |
| Recycle | OnRecycle() |
Entity returned to object pool |
Parent-child events:
| Event | Parent | Child |
|---|---|---|
| Attach | OnAttached(childEntity, parentTransform, userData) |
OnAttachTo(parentEntity, parentTransform, userData) |
| Detach | OnDetached(childEntity, userData) |
OnDetachFrom(parentEntity, userData) |
Runtime/
├── Entity/
│ ├── EntityComponent.cs # Unity MonoBehaviour bridge
│ ├── EntityLogic.cs # Base class for entity behavior
│ ├── EntityHelperBase.cs # Abstract helper for instantiation/release
│ ├── EntityGroupHelperBase.cs # Abstract helper for entity groups
│ ├── Entity/
│ │ ├── IEntityManager.cs # Core manager interface
│ │ ├── EntityManager.cs # Manager implementation (partial class)
│ │ ├── IEntity.cs # Entity interface
│ │ ├── IEntityGroup.cs # Entity group interface
│ │ └── ...
│ ├── ShowEntityInfo.cs # Show entity parameters
│ └── AttachEntityInfo.cs # Attach entity parameters
├── EventArgs/ # Lifecycle event args
│ ├── ShowEntitySuccessEventArgs.cs
│ ├── ShowEntityFailureEventArgs.cs
│ ├── ShowEntityUpdateEventArgs.cs
│ ├── ShowEntityDependencyAssetEventArgs.cs
│ └── HideEntityCompleteEventArgs.cs
└── Editor/Inspector/ # Custom Inspector
- QQ Group: 467608841 / 233840761
See Releases for changelog.
| Package | Description |
|---|---|
com.gameframex.unity.asset |
2.5.0 |
com.gameframex.unity.event |
1.1.0 |
- QQ Group: 467608841 / 233840761
See Releases for changelog.
See LICENSE.md for license information.