Hi to all
In my game i have some npc’s that have a skinned mesh renderer component, and use physics.raycat function for detecting other npc’s in front and behind of themselves in update function.I implement a object visibility system based on distance to player and camera field of view, and when npc 's are to far from player or out of camera field of view ,i disable their skinned mesh renderer component and all script attached to them among script i use for npc’s sight.
My problem is that when npc’s number is more than 3 -5 ,then my framerate is less than 15 and if i add more npc it reach to 5 or less,even if don’t see any npc in my camera view based on my object visibility system.
But if i disable all npc my framerate reach to 60.
Whats wrong with my solution?.whether disabling all scripts attached to npc and its renderer isn’t enough?
You’re assuming the drawing is the problem and not the raycasting or something else. Use the unity profiler to narrow it down. Choose Deep Profile option.
@hippocoder
thanks for reply.
As I said before when i disable npc’s, framerate is good enough .now whether disabling npc renderer and all scripts attached to them isn’t equal to disabling them?
For clarification: my npc’s use unity NavMesh and NavMeshAgent for navigating in level.
If you don’t want to profile, that’s ok but serious developers profile to get an immediate and clear answer. Unity - Manual: The Profiler window
bigbat - you’re asking what’s wrong with your solution, but you haven’t defined your problem yet. Performance hits and gains are a funny business and sometimes it’s not what you expect.
When you disable a script, you disable its Update / Fixed Update functions. Other functions can still be called. Their physics proxy will continue to interact with the world. Maybe it’s still involved with the NavMesh stuff, who knows?
At the very least, use Stats and compare the ms times you’re getting on Main Thread and Renderer. (don’t use FPS, it’s misleading)