Any Way to Create Visuals without GameObjects?

Hello,

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)

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.

https://discussions.unity.com/t/841163/2

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:

https://discussions.unity.com/t/846847/2

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.

1 Like

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.

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.

1 Like

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.