andoowhy / EgoCS

EgoCS: An Entity (GameObject) Component System framework for Unity3D
MIT License
223 stars 31 forks source link

Question about Ego.Destroy and DestroyImmediate #6

Closed theBurningVoid closed 7 years ago

theBurningVoid commented 7 years ago

I have some code designed to run at edit time and part of it needs to destroy components and GameObjects at edit time, but EgoCS only has the Ego.DestroyGameObject() and Ego.DestroyComponent(). which I've tested and they seem to not work correctly at edit time. I was wondering how EgoCS would handle me using Unity's built in DestroyImmediate() to do this task and also if I need to be concerned about EgoCS at all (using Ego.AddGameObject() and the like) in the code that will only ever run during edit time assuming i don't use the helper functions like HasComponents(). At start() during runtime do the egoComponents and other related systems check things like what components are already attached. The code I'm doing this for is a rogue-like game me and a partner are making and the way I'm designing the procedural area generation is by having a bunch of templates of rooms as prefabs (with the individual tiles as child objects and randomly choosing between them at runtime. The way I'm setting them up is attaching a script with a custom editor class to allow me to auto generate some aspects of the rooms while allowing me to tweak them in the scene, and this of course involves a lot of function calls that involve things like adding/instantiating Components and gameobjects as well as destroying them

andoowhy commented 7 years ago

EgoCS is not designed to run at editor time. Also, I have no plans to ever add an Ego.DestroyImmediate() or equivalent, since that would allow EgoConstraints and EgoEvents to have references to invalid GameObjects and / or Components.

To make your procgen code play nicer with EgoCS, you could start your procgen prefab instatiation routines right before you call Ego.Start(). You could also emit various custom EgoEvents (with Systems that can handle them) whenever you change anything with your editor script to keep EgoCS up to date.