Hello to the forum, I am trying to make an Enemy NPC system. The NPC is a Node3D which consists of a Skeleton3D (Mixamo) and an AnimationPlayer(Mixamo). I am wondering if there are better alternatives to using a Skeleton3D and BoneAttachments (perhaps I am using it wrong to be honest) in order for the CollisionShape3Ds to follow the animation of the Model. According to VerySleepy it gets expensive when I have a large number of NPCs and I only have one BoneAttachment at the moment (stress testing with 500 NPCs though ~ 50fps). I am not that experienced with debugging active processes but if I understand correctly, out of the 60 seconds I ran my project, 3,34s were spent on just Transform3D:operator, 2.19s on Animation:_find, and so on, right?
I am only stress testing, I won’t ever need that many active on screen. But even a 100 which will be necessary gets me down to 250-300 fps from 1100-1200fps, on a graybox with nothing else. I am currently not staggering the _physics_process for any NPC which might be a start but that will just delay my problem not solve it, namely these expensive operations in the screenshot above. This is more of a can I squeeze more performance out by changing my approach? Since other things down the line will start taking up CPU time as well I would like to consider this now.
Also, I would like it that the game can run somewhat smoothly on mid-range hardware.
Ok, so what you’re dong is called future proofing. It’s solving for a problem that doesn’t exist yet but you think might exist in the future. We all do it, and it’s a bad habit I personally try to avoid as much as possible.
The numbers you’re worried about are not worrisome. You can also use the Profiler, Visual Profiler, Monitors and Video RAM tabs in the debugger to get a much better idea of what your game’s performance looks like. Your approach of using an outside tool is like someone with a speed detector trying to diagnose an engine problem by using the speed at which you drove by.
You’re above 30fps so you’re fine. Also, adding up all those numbers you’re concerned about, your NPC took up 18% of the total processing time available to you. But there is no guarantee that adding more nodes will linearly increases those numbers.
You have two choices:
Option 1: Learn About Profiling
Actually learn how to profile your game. It’ll take a while and you’ll spend a lot of time jumping at shadows because you’re worried that your game might be fast enough. You can literally spend months on this before you even start actually coding your game.
Option 2: Make Your Game
Spend the time making your game. It’s more fun and less stressful than worrying all the time. You cannot extrapolate how an actual NPC is going to work with a deformed model with one bone connection. Create the game you are creating and sees how it does. Figure out where your bottlenecks are (if any), once you have your game running. Then, if you need to, learn about profiling.
Conclusion
I recommend the second option. Right now you are trying to measure something you do not understand, and is much more complex than you seem to realize. Working with it will solve those knowledge gaps and help you to make informed decisions of what needs to be streamlined and what does not.
I already used the profiler, my scripts run in under 0.3ms. Evidently, I am using something wrong in the engine or not making full use of it. I am creating my game but I am not planning on refactoring my whole codebase just to fix this later. Additionally, my rig is not the target computer I am aiming this game to run on.
Anyway for people reading that might reach this thread, what I came up with is checking the camera frustum and pausing animations when the NPC is out of the camera view. It’s very easy to set up and now 100 active NPCs sits nicely at 650-700 fps.