#ECS + Monobehaviour comunication understanding

1 messages · Page 1 of 1 (latest)

fallow talon
#

Hey everyone! Ive got a problem i cant wrap my head around at the moment, hopefully someone has had this issue before and can shed some light on it:

Im making a sort of Bullet-hell game. The user will control a group of entities that will constantly fire bullets.

Ive made a weapon selection screen (no ECS, only monobehaviour) that reads the data from an array of scriptable objects representing the weapons (guns, shotguns, etc). These scriptable objects contain a reference to a weapon prefab. The user will select a single weapon, and that weapon should be the one all player troops hold.

How can i "save" this prefab, transform it into an entity prefab and have my players entities spawn with the selected weapon? Perhaps im thinking about it wrong but im not experienced enough to know. I can share code if necesary.

Thank you in advance!

final star
#

Have you baked all necessary data for the ECS side into subscene(s) so that what you want is a way to apply those options from that selection screen to the ECS world?

#

Hypothetically, in case you already have a list of weapon models baked into a subscene, each model has a unique ID we can use to retrieve corresponding rendering info to assign to an entity, you can just send that ID to the ECS world.

fallow talon
#

I can not answer your question with security, im still a bit new to ECS and still learning my way around it.

For some context, my weapon prefabs do have autoring scripts attached to them to pass the needed information. The one thing that confuses me is if the prefabs should be within a subscene or not to be baked. Since the prefab would kind of lose its purpose if its already instantiated in scene/subscene.

#

I will take a look at that project as soon as i get back, thank you very much! Hopefuly it answers some questions

final star
#

If your weapons are baked into prefab entities then they will be excluded from all normal queries. Simulation and presentation systems won't process them.

#

Prefab entity is just an entity with a Prefab tag component.

#

In the 2D repo, EntityPrefabAuthoring will make the GameObject prefab baked into a prefab entity.

#

Then this system InitializeEntityPrefabVaultSystem makes a map out of those prefab entities for later use.

#

So for example on the selection screen the player choose weapon of ID: 2, you can just send that number to the ECS world, look up the map of weapons map.TryGetValue(weaponID, out var prefab), then proceed to instantiate it.

#

The system HandleEventChangeSpriteSheetSystem demonstrates how to do that in a way that makes ECS happy (this is important!).

#

Additionally, ECS revolves around data, so to put that weapon in the correct place relative to the player, you'll need more data at the instantiating step.

final star
#

You probably want prefab entities so you should use technique demonstrated by EntityPrefabAuthoring.

#

So you need 2 authoring scripts: 1 for your own weapon, another for authoring prefab entities.

fallow talon
#

Okay, i believe i understood the concept and got it working, thank you very much!

#

Took me a while but it kind of clicked suddenly

#

This does bring me towards another question, perhaps this is a different subject

How could ever work with a package like Adressables? If things NEED to be in scenes to be baked, how can one ever make dynamic content? In this case, i can imagine weapons being content, but if they have to be in a subscene to be baked, it defeats the whole purpose. Is there a way to go around this or is ECS just not meant to work with Addressables?

final star
#

ECS just not meant to work with Addressables

#

Yes, ECS uses a different content archive format.

#

In this case, i can imagine weapons being content, but if they have to be in a subscene to be baked, it defeats the whole purpose.

fallow talon
#

oh man, i have no idea how i missed this documentation

#

damn 💀

"The other content management solutions in Unity, such as Resources, AssetBundles, and Addressables, either don't work with Entities or are suboptimal solutions for data-oriented applications."