Entitas icon indicating copy to clipboard operation
Entitas copied to clipboard

_group.GetEntities().AsParallel().ForAll(Execute);这段语句有GC

Open 32haojiufangjia opened this issue 2 years ago • 2 comments

先生,你好,我在测试中发现这段语句有GC,请问有办法解决吗

32haojiufangjia avatar Sep 04 '23 14:09 32haojiufangjia

From Google Translate:

Hello sir, I found during testing that this statement has GC. Is there any way to solve it?

@32haojiufangjia yes, please try

_group.AsEnumerable().AsParallel().ForAll(Execute);

sschmid avatar Sep 04 '23 14:09 sschmid

Fyi, when doing things in parallel, please avoid using generated methods like entity.AddXyz(), entity.ReplaceXyz(), entity.RemoveXyz(), etc, since they result in modifying non-concurrent collections like HashSets, etc. When doing things in parallel I recommend changing the component values directly, e.g.

entity.health.value -= 1;

sschmid avatar Sep 04 '23 14:09 sschmid