Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Any Way to Create Visuals without GameObjects?

Discussion in 'General Graphics' started by jlars789, Aug 15, 2023.

  1. jlars789


    Mar 3, 2023

    I am looking to create some visual effects in the game (in my case, a status effect) appear above an enemy as an animated icon. However, in my testing, certain operations on GameObjects can be significantly slower than operations on C# objects, the latter being my current mode of implementation.

    I would prefer not having to 1) redo the work to transfer all appropriate behaviors to a GameObject and 2) worry about the potential performance issues that may come down the line due to using GameObjects when not necessary.

    I'm wondering if there is some way to create dynamic visuals *without* the use of a GameObject - something akin to a SpriteRenderer without the GameObject (although, this particular example does not seem possible)
  2. Kurt-Dekker


    Mar 16, 2013
    Then don't worry about it. We don't and our games are performant enough.

    If you really need ten billion things flying, look into ECS/DOTS.

    Otherwise your post just sounds like premature optimization overthinking. I suggest you get on with your game so that you enjoy the process and so that it actually comes into existence.

    And finally, here's the standard optimization blurb:

    DO NOT OPTIMIZE "JUST BECAUSE..." If you don't have a problem, DO NOT OPTIMIZE!

    If you DO have a problem, there is only ONE way to find out. Always start by using the profiler:

    Window -> Analysis -> Profiler

    Failure to use the profiler first means you're just guessing, making a mess of your code for no good reason.

    Not only that but performance on platform A will likely be completely different than platform B. Test on the platform(s) that you care about, and test to the extent that it is worth your effort, and no more.

    Remember that optimized code is ALWAYS harder to work with and more brittle, making subsequent feature development difficult or impossible, or incurring massive technical debt on future development.

    Notes on optimizing UnityEngine.UI setups:

    At a minimum you want to clearly understand what performance issues you are having:

    - running too slowly?
    - loading too slowly?
    - using too much runtime memory?
    - final bundle too large?
    - too much network traffic?
    - something else?

    If you are unable to engage the profiler, then your next solution is gross guessing changes, such as "reimport all textures as 32x32 tiny textures" or "replace some complex 3D objects with cubes/capsules" to try and figure out what is bogging you down.

    Each experiment you do may give you intel about what is causing the performance issue that you identified. More importantly let you eliminate candidates for optimization. For instance if you swap out your biggest textures with 32x32 stamps and you STILL have a problem, you may be able to eliminate textures as an issue and move onto something else.

    This sort of speculative optimization assumes you're properly using source control so it takes one click to revert to the way your project was before if there is no improvement, while carefully making notes about what you have tried and more importantly what results it has had.
    jlars789 likes this.
  3. jlars789


    Mar 3, 2023
    Thank you for the reply! My almost half-decade in college for Computer Science has almost forced me to try to make things as optimal as humanly possible, but I suppose if I wanted to do that, I probably should not be using Unity...

    I'll take notes of potentially slow things and fix them later if the time comes that I need to.
  4. Kurt-Dekker


    Mar 16, 2013
    Yeah, that's a school thing. Almost everything you learn in school as far as "best practices" simply aren't useful in the real world, especially the real world of game development.

    Your choices are basically:

    - rapidly unlearn such unproductive things so you can be effective
    - slowly and painfully unlearn them fighting and kicking at every step
    - simply don't unlearn them and cripple your gamedev progress forever into the future.

    Yes, don't do stupid things and waste CPU cycles / memory, but the CPU and the memory is there for you to use.

    It would be like buying a lovely new 4-bedroom house and deciding you're going to use it very optimally and only move into the little windowless closet under the stairs, in order to not waste the house's space. That would be most forms of optimization proposed here.
    Sluggy likes this.
  5. MelvMay


    Unity Technologies

    May 24, 2013
    Use the GL type or use the Graphics type to blit/draw meshes if you so wish.

    But in the future, please ask generic graphics questions on the General Graphics forum, not the 2D forum.

    I'll move your post for you.