Deactivate and restart the systems

Hello!

As I’m in the process of creating a main menu for my game, I’ve just realised that Systems is permanently active. Even in the main menu, where it should not be active. I had forgotten about that.

My question would be, how do I make sure that SystemBase or ISystem are only active in the scene where I want them to be active? I don’t need them in the main menu and when I switch from one scene to another, some SystemBase and ISystem have to be restarted.

Do you have any idea how I can do this?

Not sure if there’s a clean way to do this without manually enabling and disabling the systems. But, top of my head, you can try:

  • H̶a̶v̶i̶n̶g̶ ̶a̶n̶ ̶I̶E̶n̶a̶b̶l̶e̶a̶b̶l̶e̶C̶o̶m̶p̶o̶n̶e̶n̶t̶ ̶t̶h̶a̶t̶ ̶w̶o̶u̶l̶d̶ ̶b̶e̶ ̶r̶e̶q̶u̶i̶r̶e̶d̶ ̶f̶o̶r̶ ̶t̶h̶e̶ ̶s̶y̶s̶t̶e̶m̶s̶ ̶t̶o̶ ̶r̶u̶n̶,̶ ̶t̶h̶e̶n̶ ̶j̶u̶s̶t̶ ̶t̶u̶r̶n̶ ̶t̶h̶a̶t̶ ̶c̶o̶m̶p̶o̶n̶e̶n̶t̶ ̶o̶n̶ ̶a̶n̶d̶ ̶o̶f̶f̶ ̶t̶o̶ ̶k̶i̶n̶d̶ ̶o̶f̶ ̶"̶t̶o̶g̶g̶l̶e̶"̶ ̶t̶h̶e̶ ̶s̶y̶s̶t̶e̶m̶ ̶b̶a̶s̶e̶d̶ ̶o̶n̶ ̶t̶h̶e̶ ̶q̶u̶e̶r̶i̶e̶s̶ ̶i̶n̶ ̶i̶t̶
  • Have some sort of a manager where you - maybe have a map of <string,system> and you - can toggle systems on and off via GetOrCreateSystemManaged() or GetOrCreateSystem() and toggle their Enabled property

Aside from those two, is there a reason for you to actually touch the systems and not the entities that they need to process?

[EDIT] Touching systems instead of manipulating data seems like not the intended approach when working with data-driven architectures. Unless, you really really have to. In most cases, systems should just react to data. [/EDIT]

As a side note, this seemed to me like a very common problem to have, so someone probably already made a tool, utility, or a wrapper for this.

1 Like

The enable state of IEnableableComponent is always ignored when the system checks whether it can update or not.

https://docs.unity3d.com/Packages/com.unity.entities@1.2/api/Unity.Entities.ComponentSystemBase.RequireForUpdate.html#Unity_Entities_ComponentSystemBase_RequireForUpdate__1

2 Likes

My bad. Also saw this in a post similar to OP’s case. It can still be used for the system’s query but yes, the system will still run.

I edited the post above to not confuse other people. Thanks!

First of all, thank you very much for your answers!

I think I need to describe the problem in more detail.

My map consists of many individual entities. The appearance of my map is saved in a PNG file. I read the pixel data at the start and generate the individual entities of the map depending on the colour of the pixel.

I save the map in a BlobAssetReference. All entities belonging to the map are then stored here and can be accessed.

Saving seems to cause me fewer problems now, although I’m not finished yet. I’m currently seeing problems in the shop.

How can I explain to the system that runs the map construction from the PNG that it should possibly use other data if it is constantly active? I should have a starting point. But if my MapLoading is already active in the main menu, this does not work.

I don’t know if you see any other possibility. My idea was to load the data from the savegame first. Then start the maploader system. If there is data from the savegame it will be processed. If not, the data is loaded from the PNG.

But again, the problem is that it doesn’t work as long as the system starts immediately when the game starts.

I hope I was able to express myself clearly.