Search Unity

Will jobs help my game?

Discussion in 'Entity Component System' started by wileyjerkins, Dec 20, 2018.

  1. wileyjerkins

    wileyjerkins

    Joined:
    Oct 13, 2017
    Posts:
    77
    I have a classic Asteroids type space shooter, but each asteroid and enemy ship runs its own script. I was wondering if it would make sense to create jobs for the enemy ai each ship runs, and another for asteroids.

    The Asteroid script just throws a ray at the player to generate a hud icon in the proper location on a radar screen, but does run every frame, which it has to to keep the icons in the right spot at high velocity.

    The enemy AI script is way more complicated. It seems like that one on another core would allow me to have more enemy ships. But not sure what it means by jobs can't access global data. Right now the enemy AI does reference globals (like how many other enemies are present so they can potentially team up, run, protect starbases, etc) but I guess that could be rethought.

    Most of my CPU time is spent on physics. Can you offload physics to another core?

    The game runs OK now on my uber dev machine, but I am mesmerized by some of the demos I see with a bajillion enemies and think that would be cool purely from a "this is possible" standpoint.

    The game runs rather slowly on a biz laptop, and I think moving the enemy AI to another core might really help, but the graphics are likely the bottleneck. I need to learn more about the profiler for sure.

    Thanks for any advice for a newbie to this sort of thing.
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Hi.

    Physics in Unity 2018.x is already multi threaded.
    Unless you really have many thousands of objects, with ray casting, AIs etc, or fewer but very complex AIs, probably you won't gain much for the need.

    That saying, if you on PC, you probably fine. But if you start aiming for mobile, the ECS may become beneficial.

    Major part of optimization, comes of how you script your logic. By itself, is often the case, you can improve logic by factor of magnitude. That even before thinking about ECS.

    But from what you say, I don't expect your game having any near complex AI, to get major benefit from ECS.
    Unless again, you got thousands of them.

    Seams you should get focus now, on physics side, if that what is your bottleneck / concern.
    Find how you can improve.

    Just to say on side note, ECS will expect quite decent knowledge about programming and C#.
     
    wileyjerkins likes this.
  3. wileyjerkins

    wileyjerkins

    Joined:
    Oct 13, 2017
    Posts:
    77
    Thanks for the reply. I will leave it be then. Things seem to run fine and like you said I can likely make the enemy AI a bit more efficient first.

    Good to know about the physics being multi-threaded in 2018 ... glad I upgraded after all.