Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Can we access component data from an Entity prefab

Discussion in 'Entity Component System' started by tzxbbo, Aug 18, 2023.

  1. tzxbbo

    tzxbbo

    Joined:
    Dec 14, 2019
    Posts:
    57
    An entity prefab is an entity that has the following components:

    • A prefab tag: Identifies the entity as a prefab and excludes them from queries by default.
    • A LinkedEntityGroup buffer: Stores all children within the prefab in a flat list. For example, to quickly create the whole set of entities within a prefab without having to traverse the hierarchy.

    can we do something as below in ECS
    LocalTransform transform = SystemAPI.Getcomponent<LocalTransform>(entityPrefab)
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,976
  3. tzxbbo

    tzxbbo

    Joined:
    Dec 14, 2019
    Posts:
    57
    So we could dynamically change our entity prefab during runtime, that's a nice feature
     
  4. tzxbbo

    tzxbbo

    Joined:
    Dec 14, 2019
    Posts:
    57
    Looks like it's problematic, I'm trying to read the bounds size from an entity prefab, while it's legal to do all the get read operations, it's a default struct that contains no useful data
     
  5. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,976
    WorldRenderBounds? That's only up-to-date at runtime or for scene entities in closed subscenes. RenderBounds should be valid though, which you can transform into world space yourself.
     
  6. tzxbbo

    tzxbbo

    Joined:
    Dec 14, 2019
    Posts:
    57
    Yeah I was using WorldRenderBounds, Could you give me some hints on how to convert RenderBounds value to world, just had a check on them, they are all the same with extent (0.5, 0.5, 0.5), even on object with different scales, is there a conversion function or something.
     
  7. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,976
    AABB.Transform()

    You can find example usage in RenderBoundsUpdateSystem.cs