c# - UNITY ECS 不在运行时注册新实体
问题描述
我是新来的,希望你能解决我的小问题。
我决定在 Unity 中测试新的 ECS 系统并遇到这样的问题:
我有两个实体和一个控制它们的系统。当我开始播放模式时 - 我的系统找到了两个实体,但是当我在运行时生成第三个实体时 - 系统没有更新它。
我的系统:
public class MovementSystem : ComponentSystem
{
public struct ComponentFilter
{
public Transform m_Transform;
public MoveComponent m_MoveComponent;
}
protected override void OnUpdate()
{
var entities = GetEntities<ComponentFilter>();
foreach (var item in entities)
{
Debug.Log(item.m_MoveComponent);
}
}
}
我的组件:
[RequireComponent(typeof(GameObjectEntity))
public class MoveComponent : MonoBehaviour
{
//do nothing. may be added to another gameObject by AddComponent
//if object doesn't have GameObjectEntity - creates it
//and then system will not update it.
}
如何在我的系统中注册这个新对象?谢谢你的回答!
解决方案
如果我正确理解了这个问题,那么您还没有实例化新实体。您可以在您的 MovementSystem 中使用.EntityManager.Instantiate(Entity srcEntity)
或在另一个地方使用World.Active.GetOrCreateManager<EntityManager>().Instantiate(Entity srcEntity)
.
推荐阅读
- reactjs - 在 axios/ajax 调用中处理 Symfony 路由
- c - 错误预期)同时将结构的指针成员传递给函数
- javascript - 使用 Javascript 查找超级数字,CMD 中出现 NaN 错误
- python - 如何在不通过表单验证的情况下在 UpdateView 中进行验证?
- android - android studio 3.3 中的“包括 C++ 支持”选项在哪里?
- php - 如何修复模型之间的关系错误?
- laravel - Laravel:在单个视图中返回 2 个集合
- wordpress - 尾随斜杠与非尾随导致重复页面的问题
- javascript - 使用私有 IP 从 Google Functions 连接到 Cloud SQL
- regex - 设计:在不断创建和删除表时运行 pg_dump