#Baker change prefab component

1 messages · Page 1 of 1 (latest)

red sedge
#

I have the use case that I have a ItemAuthoring as prefab and ItemCollectionAuthoring and then ItemAuthoring prefab is drag and drop into ItemCollectionAuthoring. At ItemCollectionAuthoring, I want do modify the component ItemAuthoring prefab like to enable component, disable component, add component, remove component and etc. Is that possible to do that? If yes, what's the baker api to do that?

naive prairie
#

It is possible to alter prefabs in 'Baking', just not in Bakers you are asking about. Because Bakers are not run in a specific order, Bakers are not allowed to change anything about Entities they do not create and own. In this case, ItemAuthoring can change things on the 'prefab Entity', and ItemCollectionAuthoring can change the Entity associated with it, but ItemCollectionAuthoring is not allowed to change anything on the Entity of the prefab. What is possible however, is change the prefab Entity in Baking Systems. Baking Systems are run after all Bakers are finished and therefore can change all known Entities. If you do do that, there is one small but important detail you must know: prefabs are be default excluded from queries. So to have prefabs show up in your query, you have to use the Query<RefRO<MyComp>>().WithOptions(EntityQueryOptions.IncludePrefab.

red sedge
naive prairie
#

Both [TemporaryBakingType] and [BakingType] will only be present on the Entities during the Baking stages and will not show up in runtime. The difference is that [BakingType] is persistent within the Baking world, whereas [TemporaryBakingType] will disappear after a single Baking run. This makes [TemporaryBakingType] useful for a reactive system: only the first time after a Baker is run that adds a [TemporaryBakingType] will it be available for Baking Systems. At the end of the run, the [TemporaryBakingType] is removed. After that, if other Bakers are re-run, a Baking System checking for the [TemporaryBakingType] will not be re-run.

red sedge
naive prairie
#

If you don't use a baking-only component, your Entity will have that component in runtime as well. As this seems like data that is only needed in Baking time, it would be cleaner to use a baking-only type component.

#

In addition, it is marginally faster, as the component doesn't have to be copied over from the 'baking world' to the 'runtime world'

#

As for which to use, both types will run the baking system. It is easier to explain with an example. If you have 5 cubes in a SubScene that all have the same authoring component on it. The goal is to draw a bounding box for each of the 5 cubes. For this the authoring baker adds a [BakingType] with the min and max coordinates of the bounding box. A Baking System multiplies those coordinates by two (just making something up here). If one of the cubes in the scene is changed, it triggers the Baker of that cube. It then triggers the corresponding Baking Systems, that loops over all Entities with that specific [BakingType]. This means that for one change, 5 Entities are changed in a Baking System. However if the [BakingType] is replaced by a [TemporaryBakingType], only the newly changed cube has this component. The Baking System will ignore the 4 other Entities and recalculate only the changed one.

red sedge
red sedge