Forum rules - please read before posting.

Weird problem: player character lagging in some part of the map, and other related issues

Hello everyone,

Something strange is happening to my game. It's the first game i am developing on Unity and on AC, so there are probably some settings to set in a certain way i still don't know.

The main problem is: when the player moves around the area - delimited by Collision Cubes - in some specific points, the game lag. The points, in which the game lag when the player move, are always the same.
Here it is the video of what is happening:

Now: the movement method is "direct", input method "mouse and keyboard", but i have anyway a Navmesh on the area necessary when moving to hotspots.
I tried to low the quality at the minimum in the project settings, but nothing changed.
It seems to lag only when moving near by collision cubes or some hotspots, but i couldn't find any reason of that.

But there is more: this issue seems to create other more weird issues.
If I let the game lag and later I interact with an object with the interaction "Look At", then suddenly the main character starts to ignore any collision cubes, box colliders, and every other colliders, moving "through" the walls.
I supposed that because i was trying to resolve the player-moving-through-walls bug, and after many attempts, i arrived to the conclusion that is a consequential issues of the main game-lagging bug.

It's a lot of time that i am struggling with this problem but i really cannot understand what it can be, so any help will be really appreciated.

Ask me everything about my setting, if you need so know more and i'll answer ASAP

Comments

  • What are your AC and Unity versions?

    Let's come back to the interaction issue after the lagging, as addressing one may address the other.

    It's hard to tell from the video if this is true "lag" in the proper sense of lowering framerate, or that the player's position is just being affected. The best way to determine this is to open up Unity's Profiler window and see if you get spikes and/or framerate drops when this occurs.

    If you're getting spikes, enable "Deep Profile" so that we can see what process is causing it.

    If it's instead a player position issue, let's see a screenshot of your Player's full Inspector (including non-AC components). I find no issue with the 2D Demo's player character, Brain2D, with these settings (recommended for this style of game):

    • Checking Move with Rigidbody 2D? in his Physics settings
    • Enabling Interpolation in his Rigidbody
    • Unchecking Turn root object in 3D? and setting his Turn speed to -1 (to enable snap turning)

    If you drop the Brain2D prefab into your scene (from /AdventureCreator/2D Demo/Resources) and make the same changes, does he also suffer the same problem as your own Player?

    One other thing to consider is the use of Physics Materials on either your Player's or your walls' Collider components, as this can be used to reduce friction when two physics objects are pushed together.

    About Hotspots: a Hotspot should not block a character's movement unless it's collider has Is Trigger unchecked - is this the case for Hotspots that give such an issue?

  • Hi Chris,
    Thank you for the reply and sorry for late answer.
    I'm using Unity 2018.3.14 and Adventure Creator 1.64.5

    I tried to open Unity's Profiler and i get the spikes and the framerate drops. So I guess it's lagging.

    I tried to change the player settings as you requested, but nothing changed.
    ( in the image below i put back to the original value some settings)

    I tried to import the prefab of Brain2D, changing his settings, and i could see a small improvement, but still lagging.

    Here is my player inspector: https://imgur.com/a/nwm974I

    About materials: i use only one material for many sprites, but not for the Colliders. Anyway the material is this one: https://imgur.com/a/wf8kFgm

    But going back to the main problem: i enabled the Profiler, i get spikes, so i enabled "Deep Profile" and it seems the problematic processes are "Physics" and "Animation", but still don't know how to solve it.
    Here is a video of the lagging with Deep Profile activated.

  • The video shows the spikes, but not the causes. Pausing the game and clicking on the spike will reveal more information about it.

    Please also try this with the latest version of AC (in a duplicated project, just for testing) so that we can rule this out as an already-addressed issue.

  • I tried with the latest version of AC but the problem is the same.

    I screenshot two cases of lag, clicking on the spikes:
    https://imgur.com/a/G7M2R4O

    If I'm reading it right, the problem is in the NPC.followUpdate and in the polygon colliders, but i'm absolutely not sure. And still don't know how to proceed to solve it.

    P.S.: Enabling the "Deep Profile" seems to change nothing, I see exactly the same stuff, so maybe I'm not looking the correct spec

  • Are you instructing any NPCs to follow anyone? This is typically done using the Character: NPC follow Action. If so, temporarily stop this from running and see what impact it has on performance.

    There can be a performance hit to such an operation if you set a very low Update frequency (s) value, and the NavMesh itself is made up of many vertices. How complex is the NavMesh? Let's see some images of the Action and the NavMesh's Inspector. It may be worth reducing the Accuracy slider down, but let's see what we have.

  • Yes, i have an NPC following the main character.
    I tried to remove that following action and now it doesn't lag anymore. I have a very low update frequency (0.2 s) because i would like the NPC never goes out of the camera.

    I enabled again the following action, with an higher update frequency but the problem remain.
    I think the problem occurs every time the following action update itself, because if I set 2 seconds of update frequency, it lag every 2 second, more or less.

    The point is, I don't really care about lagging, but this lag create another side effect, another problem, the one I wrote on the first post: after the lagging, the player can walk through the Collision Cubes (absolutely don't know why).

    The NavMesh, so far, is just a rectangle with some holes, nothing complex.

    I thank you a lot for locating the problem. Any idea on how to solve it?

    Some images below.
    https://imgur.com/a/8OwmTmF

  • edited September 2019

    Can you share more about the NavMesh's complexity with real numbers. So the base just has four vertices? How about each of the holes?

    This may also be affected by your game's scale. How does your player character's size compare with e.g. the 2D Demo game's, Brain2D, when placed side-by-side?

    Yes, the lag itself is tied to the frequency - because it's here that the character generates a new path to the player.

    Try reducing the NavMesh's Accuracy slider, as well as temporarily disabling character evasion - do either of those make a difference?

    That this ultimately affects the collision system sounds like it may be an issue with Unity itself, so you could try playing with Unity's Physics or Time settings (like reducing the Fixed Timestep or raising the Solver Iteration Count). Setting the player's Rigidbody 2D Collision Detection to Continuous may also improve things.

  • Ok so: thanks to you the issue seems to be fixed, but now if you can be so gentle to explain why is this happening, i will appreciate a lot.

    Here below there is an image of the navmesh (is just a polyogn collider with 5 vertices).
    Every hole has a Box Collider, instead of a Polygon collider, so there are 4 vertices each hole.
    https://imgur.com/a/WZU0zLd

    Brain 2D is bigger than my character, more or less is double size.

    I tried to reduce Accuracy slider to 0.30 and disabled character evasion. With this changes it works.
    I even put back the character following Update Frequency to 0.5 and still works fine.

    My question now is: what is that accuracy slider and character evasion? and why it is now working?

    Thank you a lot for the help, really. :)

  • I tried to put back Accuracy to 1.00, with character evasion disabled, and it's working.

    I tried to enable character evasion with Accuracy set to 0.50, and it's working.

    I tried to set Accuracy to 0.9 with character evasion enabled, and than it's lagging.

    It seems the problem is a combination of accuracy slider and character evasion

  • Character evasion involves dynamically altering the NavMesh at runtime by cutting holes around characters - so that other characters don't walk through them.

    Both this, and calculating paths in general, are intensive processes. The more you instruct it to do (i.e. add such holes, increase the frequency of path recalculations etc) the more you run the risk of lagging.

    When it comes to the pathfinding algorithm, scale is a factor. See the start of the Manual's "Preparing a 2D scene" chapter - the default NavMesh settings are set up to assume a scale of roughly 1 unit = 1 metre (assuming your characters are of average human height).

    Depending on the result of playing with the Accuracy / Character evasion fields, however, you may be just fine how things are. I would recommend seeing if you can find a combination of values that work for you.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.