#Where to place GOs that track/follow an Entity?

1 messages · Page 1 of 1 (latest)

summer thorn
#

Hi, I am using 2D by having some GameObjects that follow my Entities. I see multiple ways to go:

  1. Create Gameobjects in the scene and put them as properties on my Gameobject which is then baked into an entity (and adds a ComponentObject pointing to authoring.toTrack).
  2. Do the same but use prefabs which I instantiate in the the baking process. This seems buggy to me -> Multiple Gameobjects are sometimes created, and they don't seem to be destroyed when the game ends.
  3. Another way?

Then I have some managed systems, that just copy the entity position to the ToTrack.Value.transform.position to have the gameobject follow the entity. Is this the way to go? And which of the ways 1-3 is preferred?

worldly comet
#

Why not just place them in a component on entity?

summer thorn
#

Yes thats where they will go, I'll put them there during the baking process. The question is where I should get them from (Should the baked GO get a Prefab or another GO)

#

Both ways didn't work seemless when I tried them first (When just getting a GO, its position was not really updated, when getting a Prefab, the issues outlined in 2. happened), so I thought maybe I am missunderstanding something

worldly comet
#

you can only put prefab reference

#

as you can't instantiate in neither baker nor baking system

summer thorn
#

In baking system I can't instantiate new gameobjects from a Prefab?

#

Where do I instantiate the prefab then?

worldly comet
#

only runtime

summer thorn
#

So how do I do it then? I add a component during baking which informs another system that a GO should be instantiated?

worldly comet
#

add comp with prefab reference

#

have a system that seeks entities with that comp, but without other comp and adds that comp (instantiates prefab)

#

when entity has no prefab comp - system removes that other comp with instantiated go reference

#

other comp should be cleanup component and IDisposable

summer thorn
#

Thanks!

Can't I just have a PrefabToAdd component
Then a system that queries for PrefabToAdd, removes PrefabToAdd and adds InstancedGO?

#

What is a cleanup component?

worldly comet
#

it's a component that prevents entity from being destroyed

#

until that it's removed explicitly

worldly comet
#

allthough, maybe IDisposable will do that job

#

if comp is managed, Dispose will be called

summer thorn
#

When do they call dispose? When the game ends?

worldly comet
#

when component is removed afaik

summer thorn
#

So all i have to do is inherit IDisposable for both ``PrefabToAdd andInstancedGO`, and then when the game ends they will be destroyed automatically?

#

ah ok, so when the game ends I should automatically remove InstancedGO?

#

*not automatically, manually

worldly comet
summer thorn
#

Ok, that link helped with disopsable