Search Unity

Motorsports Dynamics Engine a.k.a. MoDyEn.

Discussion in 'Works In Progress - Archive' started by Ravel, Mar 3, 2012.

  1. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    ok, managed to find a big resource sucker. As I was suspecting the reflection prove was kind of a black hole cause was set to realtime check cpu and now just takin 4-5ms . Still bottleneck but that is understandable cause the card is way newer. Still would feel more comfortable in the 2ms range.

    upload_2018-1-25_23-30-14.png
     
  2. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
    hello, you could share. what you did exactly please.
     
  3. ZGoodwin

    ZGoodwin

    Joined:
    Jul 14, 2017
    Posts:
    31
    He turned off realtime check cpu for reflections.
     
  4. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    YEs and dissable carfx script cause there is something in the update in there that is extremelly taxing, likely the bone, I've not have time to check but obviously this script has to come back to life as it does hold importante visual stuff but can not come at the actual cost. No clue yet on why so much spikes.
     
  5. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
    yes. in the carfx script the material method. I use. for loops. and the performance increased. at 1auto. cpu 1.5ms
     
  6. robc

    robc

    Joined:
    Feb 15, 2010
    Posts:
    13
    Hi all,

    Was wondering if anyone’s actually been using this in a project, and particularly using Force Feedback with a non-Logitech Wheel (specifically a Thrustmaster T500). We’re potentially investigating purchasing this for a project at work, but unsure at this point how well this works with non-Logi wheels.
     
  7. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    I had no time to do more tests since I posted, has anyone have time to look to profiler spikes source?
     
  8. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    Hi>>
    I was busy for some weeks porting a game to WS. And got disconected from devleoping the racing game.
    I'll start back tomorrow after installing 2018 b7 . Was wondering if aside of the modifications I suggested does anyone found ways to further improve performance?. Anyone played with Timestep?
    Anyone does have contact with Ravel? Seems quite disconnected :\
     
  9. facundogalella

    facundogalella

    Joined:
    Mar 5, 2016
    Posts:
    57
    I was wondering if someone use this asset to 'non drifting cars': I tried to contact with the autor but I haven't luck at the moment.

    I'm keeping this topic of the resources problem too, is a quite important point.
     
  10. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    Dev posted in youtube regular racing BMW not too long ago so yes.
     
    facundogalella likes this.
  11. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    On 2018.1 b7
    Performance is better. Almost never goes behyond 3ms CPU and it fluctuates between 300-360 fps. due to spikes. This is with above mentioned script dissabling etc.
     
  12. facundogalella

    facundogalella

    Joined:
    Mar 5, 2016
    Posts:
    57
    Thank you, I run the demo in around 60 fps with the best quality, and with only 1 cars, there was a bit worried by that and I was reading this topic too
     
  13. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    You may consider waiting bit more because I had issues on the build as physics where not working but I may have touch something.

    There is also something interesting happening. After dissabling even the ui the FPS does sky rocket in stats panel up to 400FPS but in the FPS counter is like 200FPS. I ran another FPS counter and same 200FPS.
    Then I did the build and saw physics not working. So, not sure about witch one is the real one. Wonder if there is any reason for the stats panel fps not to be real.

    Anyway the demo is limited because of Vsync.
     
    facundogalella likes this.
  14. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    OK I confirm tehre is an issue when making a build, car wont move and is like dug into the track. Works fine in editor
    upload_2018-2-20_12-15-15.png

    EDIT: looking the log found this:

    Failed to load 'H:Builds/car_Data/Plugins/MoDyEnPhysics.dll', expected x64 architecture, but was x86 architecture. You must recompile your plugin for x64 architecture.

    Tested to delete the existing dll and replace for the x64 one renamed and works. I guess there is a way to map dll in unity5 so will check

    EDIT2: from help:

    On Windows and Linux, plugins can be managed manually (e.g, before building a 64-bit player, you copy the 64-bit library into the Assets/Plugins folder, and before building a 32-bit player, you copy the 32-bit library into the Assets/Plugins folder) OR you can place the 32-bit version of the plugin in Assets/Plugins/x86 and the 64-bit version of the plugin in Assets/Plugins/x86_64. By default the editor will look in the architecture-specific sub-directory first, and if that directory does not exist, it will copy plugins from the root Assets/Plugins folder instead.

    Note that for the Universal Linux build, you are required to use the architecture-specific sub-directories (when building a Universal Linux build, the Editor will not copy any plugins from the root Assets/Plugins folder).

    EDIT3:
    Placing plugin on its own folder does not solve issue you've to specifically use the one needed. Its weird because the demo has both of them and it launches properly.
     
    Last edited: Feb 26, 2018
  15. user099

    user099

    Joined:
    May 29, 2015
    Posts:
    25
    Please check if the dll´s are in the plugins folder of your build.
     
  16. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    In the demo car when going fast and trying to brake noticeabily the car oversteers and I lose control. WHat param should I modify to avoid this behaviour?

    edit: reducing brake pressure around 45% fixed this.
     
    Last edited: Feb 21, 2018
  17. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    EDIT:
    Increasing final gear ration increases the torque on all gears ate the cost of max speed
    Also increasing gear ratio of 1 & 2 gear did the trick.
    Check this channel:
    Engineering Explained

    I need some help with the setup. I'm messing arround values to understand the system.

    I cant seem to understand how to tweak values so I can get a powerfull output at low speeds. I'm looking to be able to take turns with a lot of power similar to a rally car. Atm the car gets totally stuck at low power in an uphill 180 turn.

    somethign like this:


    My issue is that when I do the drift when I whant to face the straight after the 180 turn the car is totally stuck and does not take off.

    I was asuming it would be gear ratio. Thinking that a ratio like 2:1 would give me that but is not.
     
    Last edited: Feb 21, 2018
  18. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    Checking the scripts I believe theat the performance hit of some initially not to be expensive scripts comes from the extense usage of Update()

    for instance in UI script 4 funcs are called

    UpdateReplayUI();
    UpdateUIPanels();
    UpdateCarUI();
    InitialiseUISubPanels();

    and for instance one of theese evaluates a swtich case and in gameplay it will be avaluating multiple bools and setting false ui panels each frame. Total overkill. Kind of method you would call only once in case of an event.

    furthermore using update for ui may be like an overkill overall because if you target VR with like 120FPS you'll be making totally unnecesary updates. Would use something like fixed update may be for time counters and such.

    The size of ui script is also quite considerable I will probably chop into specific parts.

    For an start I'm going to strip everything but

    Input + Surface manager

    Surface manager is super taxing and looking at the code same story. Update is callint a surface detection method that really is no cheap.
    For each wheel, gets renderer, gets material (some taxing operations in there) and asigns each wheel the surface frictions and other values of the material is hitting.

    That is the classic overkill pattern followed in other scripts. Muliply that by 4 wheels for each car.

    Surface type detection is that kind of things you need to know for sure so I'll be trying different approaches. I'll try using Gameobject.tag instead of materials .

    I think also the raycast operations should be done only when the renderers ar visible so other vehciles dont do raycasting and such.

    wheel.hit.transform.gameObject.GetComponent<Renderer>()

    I guess going to the material level and or triangle level gives you controls so if you've a complex shader you could trigger fx and sounds like could happen with a watter puddle but as it is now takes too much performance. But also the suftace friction values on wheels should only be set when surface is changed etc...

    EDIT: THIS PARAGRAPH IS WRONG:
    In regards to input the gamepad inputs needs complete rework in regards to steering. I'll direclty create a new path for gamepad steering because mapping direclty steering to the -1 1 range of the input ends up in an oversensitive steering that makes the car undrivable with precission.

    correction:
    Is the car FX that needs some tweaking as input is aparently correctly done frame rate independent ly. The car fx rotatables instead, steering wheel related seems need some rework.

    EDIT: this is partially wrong
    Finally what worries me is that it works in editor but builds dont. What unity versions are you using?

    correction:
    on the build, unlike in editor is not able to reach proper dll. Temporary fix is to have the correct dll in plugins and delete the other, you will need to rename the 64 without 64
     
    Last edited: Mar 15, 2018
  19. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    SURFACE MANAGER
    Been busy with track modelling, colliders and such so till now I had not time to mess with teh code.

    You may remember I complaint about too complex stuff taking place in update cycles.

    I've just modified Surface manager. Instead of getting materials of hit surface it does get the hit surface's tag.
    The existing material grab method was extremelly taxing.

    Dissable this part of the code:


    Code (CSharp):
    1. //OLD COMPUTE HEAVY CODE
    2.                             /*
    3.                             Renderer r = DetectRenderer(w);
    4.                             if (r)
    5.                             {
    6.                                 foreach (TrackSurface s in surfaces)
    7.                                 {
    8.                                     s.onSurface = false;
    9.                                     if (s.materials!=null)
    10.                                     {
    11.                                         Material dm = DetectMaterial(w.hit, r);
    12.                                         for (int i = 0; i < s.materials.Length; i++)
    13.                                         {
    14.                                             if (s.materials == dm) s.onSurface =true;
    15.                                         }
    16.                                         if (s.onSurface)
    17.                                             if (c == playerCar)
    18.                                                 playerOnTrack = s.skidOnly;
    19.                                     }
    20.                                 }
    21.                             }
    22.                        
    23.                             */

    add this instead:


    Code (CSharp):
    1.   //surface stimation lite version
    2.                             foreach (TrackSurface s in surfaces)
    3.                             {
    4.                                 s.onSurface = false;
    5.                                 if (w.onGround) {
    6.                                     if (w.hit.transform.tag.Equals(s.name))
    7.                                     {
    8.                                         s.onSurface = true;
    9.                                         if (c == playerCar) playerOnTrack = s.skidOnly;
    10.                                     }
    11.                                 }
    12.  
    You just need to create a tag per each surface type you create and assign each mesh with that tag. You can get rid of material variable I believe, have not yet clean up the whole script. edit: yes you can.

    Furthermore I will consider to store the current per wheel last hit surface and compare with current, this could avoid running setsurface unnecesarily.
    }
    Also avoid new variable declarations in update, script is not that big to lose track of variables.
     
    Last edited: Mar 16, 2018
  20. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    CAR FX
    This is a major resource sucking script.
    In the first place you'll probably whant to tidy up a bit.

    As the developer already is aware of UpdateMaterials() is the performance issue.

    I recommend you separate all the lights related code in this method to a separate method like UpdateLights().

    Update lights and Update materials as they're now require optimizations. I've not yet have time to get into Update lights but the performance hit occurs from // Light intensity and below lines. at a first glance it is clear that there seems to be an abuse of foreach in Update.

    So in Update Materials you're left with Tire deformation and Caliper coloring code. You may even add a bool at top as you will (I do) likely whant to have this as optional for only high end CPU players. As visually it is not much aparent and reseource wise is costly.

    Whatever is the case you will whant to convert right after the // Per wheel! line

    Code (CSharp):
    1.  foreach (Renderer r in GetComponentsInChildren<Renderer>()) {
    2.  foreach (CarWheel w in car.wheels)
    3.             {
    4. }
    as car fx is on each car root the code avove will per each object and the sampel cars has a S***load of renderers, so per each one will run a forach wheel loop, so 4x go trouh all the previous renderers setting shader values when available.

    so lets say car has 64 parts. 64x4x64 operations, some more taxing than others, per update cycle

    to
    Code (CSharp):
    1. foreach (CarWheel w in car.wheels)
    2.             {
    3.             foreach (Renderer r in w.transform.GetComponentsInChildren<Renderer>()) {
    Instead you'll per each wheel, perform a chilren renderer grab on the wheel object. So
    4x5(actual child number) operations per update cycle

    Still in teh last one you're performing a get component in update, that seems too costly. Ideally the components you whant to reach would be stored on an array and you'll acces them directly. BUT, I can see this being more complicated as there could be more than 4 wheeled vehicles and if you store in a dictionary accesing the dictionary could be more taxing than grabig component so for now I'm leaving it as is.

    EDIT:As "car" variable is already specific to teh current car( In previous paragraph I was thinking of carfx as a global singleton like script, the wheels are referred to a unique vehicle, so you can store the renderers in a renderer array at start and avoid doing a get component in update.

    EDIT2: I ran into a pretty crazy situation, I wonder if this is a bug or am I missing something.
    I did cache the renderers on start. By doing so the materials wont be assigned back into the renderer. I leave this as is for now.

    Code (CSharp):
    1. void UpdateMaterials()
    2.     {
    3.             // Per wheel!
    4.             foreach (CarWheel w in car.wheels)
    5.             {
    6.                 foreach (Renderer r in wheel_rends) {
    7.                     Material[] materials = r.materials;
    8.                     foreach (Material m in materials)
    9.                     {                  
    10.                         //TIRE DEFORMATION
    11.                         SetShaderFloat(m, "_SlipAngle", -w.slipAngle);
    12.                         SetShaderFloat(m, "_SlipRatio", -w.slipRatio);
    13.                         SetShaderFloat(m, "_Deflection", 0.5f);
    14.                         SetShaderFloat(m, "_SpeedRatio", Mathf.Clamp01((w.angularVelocity - 10) / 30));
    15.                                      
    16.  
    17.                     //BRAKES EMISSION
    18.                     float heat = Mathf.Clamp01(w.brakeTemp / 400);
    19.                         SetShaderColorIntensity(m, "_EmissionColor", heat);
    20.  
    21.                 }
    22.                 r.materials = materials;
    23.             }
    24.         }      
    25.     }
    wheel rends are the cached renderers. If it was working I would further narrow on Start to the very specific renderers by tagging the elements to modify so unnecesary loops are chopped but I need to get it to work first. It is insane, as soon as I make a direct reference in update it does get back to work, but in teh other hand the renderers seem to be correctly reached as I did some debug.log. It seems like the r.materials=materials fails when renerers are not directly referenced in update....

    I opened a thread on the cached renderers:
    https://forum.unity.com/threads/unable-to-reassign-materials-on-cached-renderers.522028/

    EDIT3:
    First of all, Updatelights() should instead of be called from update be called from Cardynamics when any of the lights or events that cause the lights to change do occur. Yet, t his is not what is killing performance, is the way renderers are accesed. CarFX instead of having public fields fro materials should have public field for GAMEOBJECTS as later on looking for the proper renerer is killing performance. Script should gather material for each light type fro the renderer rather than having theese to be asigned one by one. But wont modify this until I fix previous step as this wil lead to same no exit corridor.


    EDIT4
    jschieck, in the thread I linked avobe, pointed what I was doing wrong. I'll post a fixed/updated version soon.

    EDIT5
    Fixed!. Will post after lunch in this edit5 . It took me a while because I wanted to avoid use of dictionary unles there was no other way.

    add this variables:
    Code (CSharp):
    1.  
    2.     //New variables
    3.     Material[] temp_mats; // temporary material holder for update loops
    4.     Renderer[] tyre_rends; //all deformable tyre renderers FL FR....
    5.     Renderer[] bDisc_rends; //all brake disc renderers FL FR....
    Start()

    Code (CSharp):
    1. //for Tyre and Caliper material update, renderer caching
    2.  
    3.         tyre_rends  = new Renderer[car.wheels.Length ];
    4.         bDisc_rends = new Renderer[car.wheels.Length ];
    5.  
    6.         int k = 0;
    7.         int m = 0;
    8.  
    9.         foreach (CarWheel w in car.wheels)
    10.         {
    11.             Renderer[] temp_rends = w.transform.GetComponentsInChildren<Renderer>();
    12.  
    13.             foreach (Renderer r in temp_rends) {
    14.                 if( r.transform.tag.Equals("DeformableTyre") )
    15.                 {
    16.                     tyre_rends[k] = r;
    17.                     k++;
    18.                 }
    19.  
    20.                 if (r.transform.tag.Equals("BrakeDisc"))
    21.                 {
    22.                     bDisc_rends[k] = r;
    23.                     m++;
    24.                 }
    25.             }
    26.         }    
    And in update

    Code (CSharp):
    1.  void UpdateMaterials()
    2.     {
    3.             if (deformableTires) {
    4.                 int i = 0;
    5.                 foreach (Renderer r in tyre_rends)
    6.                 {
    7.                     temp_mats = r.materials;
    8.                     foreach (Material m in temp_mats)
    9.                     {
    10.                         //TIRE DEFORMATION
    11.                         SetShaderFloat(m, "_SlipAngle", -car.wheels[i].slipAngle);
    12.                         SetShaderFloat(m, "_SlipRatio", -car.wheels[i].slipRatio);
    13.                         SetShaderFloat(m, "_Deflection", 0.5f);
    14.                         SetShaderFloat(m, "_SpeedRatio", Mathf.Clamp01((car.wheels[i].angularVelocity - 10) / 30));
    15.                     }
    16.                     r.materials = temp_mats;
    17.                 i++;
    18.                 }
    19.             }
    20.      
    21.             int j = 0;
    22.             foreach (Renderer r in bDisc_rends)
    23.             {
    24.                 temp_mats = r.materials;
    25.                 foreach (Material m in temp_mats)
    26.                 {
    27.                     //BRAKES EMISSION
    28.                     float heat = Mathf.Clamp01(car.wheels[j].brakeTemp / 400);
    29.                     SetShaderColorIntensity(m, "_EmissionColor", heat);
    30.                 }
    31.                 r.materials = temp_mats;
    32.                 j++;
    33.             }
    34. }
    Instead of Update I'm moving this to Fixed Update because atm the framerate is quite high and the fixed update is set to 60fps. If you target VR you'll be running in update stuff that is totally not needed to be computed so often.

    This can be done in several ways but I ended upt with this solution to make uses of Arrays and avoid Dictionaries. You need to tag tyres and bDisc in editor. You should use a template car properly setup or build an editor that tags everything correctly and places objects in teh correct order.
    If you wont be having more than 4 wheels you could alternativelly create a render array per wheel and run slightly modified original code etc... but this is pretty fast as it is almost unoticeable, also I've a bool in case I just whant to run tire deformation in the players car. You could add a bool for brake caplipers too if needed etc... I go now with the lights.

    In regards to tyre deformation shader I've noticed that the shape parameter does not change. I guess this should be modified by the shader( have not looka at this) but for sure this is not accessed from the update.

    You may also need to set CarFX scriptexectuion order to something like 150, 50 would asl work I believe.

    EDIT6
    OK this is the final fix of CarFX I submit, and probably there is no need for more. I'll check the remaining parts but the resource sucking parts of the script are fixed.
    There is just one part of the script that is a bit cheesy and that I speedhardoced is that part on //lights cachingn when I do size the renderers arrays.
    You will need to
    1) have a project standard and define a fixed array size that fit your needs
    2) a dynamic resizing pass so you will do a foreach ... go rtough each tag and dimension the array accordingly prior to adding renderers.

    I've created theese tags so far:
    Road
    DeformableTyre
    BrakeDisc
    Lights_Head
    Lights_Brake
    Lights_Revers
    Lights_Position
    Lights_Direction_R
    Lights_Direction_L

    In regards to the solution in update I've kept the shader value modification for lights, as for the moment I've no per object glow shader as I had in 4.7 and I wont be doing this kind of visual tweaks till the end of the project. What is more important here is that update does not constantly asing values and is not constantly looping trough a lot of renderers. Shaders and lights will only be updated when there is need for it like hwen is braking or brake is off but lights still on etc...

    After fixing CarFX and Surface manager framerate has skyrocketed leaving much more room for graphics usage on the CPU.

    The other resource sucker is the UI script but I'm not touching that as I'll probably do my own from scratch. I suspect very same thing as in theese scripts will be going on, UPDATE cloged :D. I've once finished moved all but rotatables to fixed update and has also allowed from some extra fpss

    Added variables:
    Code (CSharp):
    1.     //New light variables
    2.     Renderer[] lights_headlights_rend;
    3.     Renderer[] lights_brake_rend;
    4.     Renderer[] lights_reverse_rend;
    5.     Renderer[] lights_position_rend;
    6.     Renderer[] lights_indicator_R_rend;
    7.     Renderer[] lights_indicator_L_rend;
    Start()
    Code (CSharp):
    1.  
    2. // LIGHTS caching
    3.         int i_ = 0;
    4.         int j_ = 0;
    5.         int k_ = 0;
    6.         int m_ = 0;
    7.         int n_ = 0;
    8.         int r_ = 0;
    9.         DimensionLightRendererArrays();
    10.  
    11.         Renderer[] temp_light_rends = GetComponentsInChildren<Renderer>() ;
    12.             foreach (Renderer r in temp_light_rends)
    13.             {
    14.                 if (r.transform.tag.Equals("Lights_Head"))
    15.                 {
    16.                     lights_headlights_rend[i_] = r;
    17.                     i_++;
    18.                 }
    19.                 if (r.transform.tag.Equals("Lights_Brake"))
    20.                 {
    21.                     lights_brake_rend[j_] = r;
    22.                     j_++;
    23.                 }
    24.                 if (r.transform.tag.Equals("Lights_Reverse"))
    25.                 {
    26.                     lights_reverse_rend[k_] = r;
    27.                     k_++;
    28.                 }
    29.                 if (r.transform.tag.Equals("Lights_Position"))
    30.                 {
    31.                     lights_position_rend[m_] = r;
    32.                     m_++;
    33.                 }
    34.                
    35.                 if (r.transform.tag.Equals("Lights_Direction_R"))
    36.                 {
    37.                     lights_indicator_R_rend[n_] = r;
    38.                     n_++;
    39.                 }
    40.                 if (r.transform.tag.Equals("Lights_Direction_L"))
    41.                 {
    42.                     lights_indicator_L_rend[r_] = r;
    43.                     r_++;
    44.                 }              
    45.         }
    46.  
    47.         //Reset lights
    48.         UpdateBrakeLightFX();
    49.         UpdateHeadLightFX();
    50.         UpdateReverseLightFX();
    51.         //indicators should be added  
    52.  
    53.  
    Update lights is called from fixed update

    Code (CSharp):
    1.  void UpdateLights()
    2.     {
    3.         //Headlights
    4.         if (car.lightsOn)
    5.         {
    6.             headlightEmission += Time.deltaTime / 0.1f;
    7.             headlightEmission = Mathf.Clamp01(headlightEmission);
    8.  
    9.             UpdateHeadLightFX();
    10.         }
    11.  
    12.         else if (!car.lightsOn && headlightEmission > 0) {
    13.             headlightEmission -= Time.deltaTime / 0.1f;
    14.             headlightEmission = Mathf.Clamp01(headlightEmission);
    15.  
    16.             UpdateHeadLightFX();
    17.         }
    18.         //----------------------------------------------------------------
    19.  
    20.         //Brakelights
    21.         if (car.brakesOn) {
    22.             brakelightEmission += Time.deltaTime / 0.1f;
    23.             brakelightEmission = Mathf.Clamp01(brakelightEmission);
    24.  
    25.             UpdateBrakeLightFX();
    26.         }    
    27.         else if (!car.brakesOn && brakelightEmission > 0) {
    28.             brakelightEmission -= Time.deltaTime / 0.1f;
    29.             brakelightEmission = Mathf.Clamp01(brakelightEmission);
    30.  
    31.             UpdateBrakeLightFX();
    32.         }
    33.         //----------------------------------------------------------------
    34.  
    35.         //Reverselights
    36.         if (car.reverseOn) {
    37.             reverselightEmission += Time.deltaTime / 0.1f;
    38.             reverselightEmission = Mathf.Clamp01(reverselightEmission);
    39.  
    40.             UpdateReverseLightFX();
    41.  
    42.         }
    43.         else if (!car.reverseOn && reverselightEmission>0) {
    44.             reverselightEmission -= Time.deltaTime / 0.1f;
    45.             reverselightEmission = Mathf.Clamp01(reverselightEmission);
    46.  
    47.             UpdateReverseLightFX();
    48.         }
    49.     }
    50.  
    51.  
    52.     void UpdateHeadLightFX()//Includes position lights
    53.     {
    54.         // Shader
    55.  
    56.         //Headlights
    57.         foreach (Renderer r in lights_headlights_rend)
    58.         {
    59.             Material[] materials = r.materials;
    60.  
    61.             foreach (Material m in r.materials)
    62.             {
    63.                 SetShaderColorIntensity(m, "_EmissionColor", headlightEmission);
    64.                 SetShaderColorIntensity(m, "_TintColor", headlightEmission);
    65.             }
    66.             r.materials = materials;
    67.         }
    68.  
    69.         //Positionlights
    70.         foreach (Renderer r in lights_position_rend)
    71.         {
    72.             Material[] materials = r.materials;
    73.  
    74.             foreach (Material m in r.materials)
    75.             {
    76.                 SetShaderColorIntensity(m, "_EmissionColor", headlightEmission);
    77.                 SetShaderColorIntensity(m, "_TintColor", headlightEmission);
    78.             }
    79.             r.materials = materials;
    80.         }
    81.  
    82.         // Light Objs //there are  no field atm for position light obj.
    83.         foreach (Light l in headlight.light)
    84.         {
    85.             if (l)
    86.             {
    87.                 l.intensity = headlightEmission;
    88.                 l.enabled = (headlightEmission > 0.01f);
    89.             }
    90.         }
    91.     }
    92.  
    93.  
    94.     void UpdateBrakeLightFX() {
    95.         // Shader
    96.         foreach (Renderer r in lights_brake_rend)
    97.         {
    98.             Material[] materials = r.materials;
    99.  
    100.             foreach (Material m in r.materials)
    101.             {
    102.                 SetShaderColorIntensity(m, "_EmissionColor", brakelightEmission);
    103.                 SetShaderColorIntensity(m, "_TintColor", brakelightEmission);
    104.             }
    105.             r.materials = materials;
    106.         }
    107.  
    108.         // Light Objs
    109.         foreach (Light l in brakelight.light)
    110.         {
    111.             if (l)
    112.             {
    113.                 l.intensity = brakelightEmission;
    114.                 l.enabled = (brakelightEmission > 0.01f);
    115.             }
    116.         }
    117.     }
    118.  
    119.  
    120.     void UpdateReverseLightFX() {
    121.         // Shader
    122.         foreach (Renderer r in lights_reverse_rend)
    123.         {
    124.             Material[] materials = r.materials;
    125.  
    126.             foreach (Material m in r.materials)
    127.             {
    128.                 SetShaderColorIntensity(m, "_EmissionColor", reverselightEmission);
    129.                 SetShaderColorIntensity(m, "_TintColor", reverselightEmission);
    130.             }
    131.             r.materials = materials;
    132.         }
    133.  
    134.         // Light Objs
    135.         foreach (Light l in reverselight.light)
    136.         {
    137.             if (l)
    138.             {
    139.                 l.intensity = reverselightEmission;
    140.                 l.enabled = (reverselightEmission > 0.01f);
    141.             }
    142.         }
    143.     }
    144.  
    So far, it may even be a good idea to move all teh lighting stuff to a separate script.
    It is probably safe to delete material fields in inspector, forgot to wipe and test

    EDIT7
    added auto array sizing
    Code (CSharp):
    1. private void DimensionLightRendererArrays() {
    2.        
    3.         int i_ = 0;
    4.         int j_ = 0;
    5.         int k_ = 0;
    6.         int m_ = 0;
    7.         int n_ = 0;
    8.         int r_ = 0;
    9.  
    10.         Renderer[] temp_light_rends = GetComponentsInChildren<Renderer>();
    11.         foreach (Renderer r in temp_light_rends)
    12.         {
    13.             if (r.transform.tag.Equals("Lights_Head"))   i_++;          
    14.  
    15.             if (r.transform.tag.Equals("Lights_Brake"))  j_++;          
    16.  
    17.             if (r.transform.tag.Equals("Lights_Reverse")) k_++;          
    18.  
    19.             if (r.transform.tag.Equals("Lights_Position")) m_++;
    20.  
    21.             if (r.transform.tag.Equals("Lights_Direction_R")) n_++;
    22.  
    23.             if (r.transform.tag.Equals("Lights_Direction_L")) r_++;
    24.            
    25.  
    26.             lights_headlights_rend = new Renderer[i_];
    27.             lights_brake_rend = new Renderer[j_];
    28.             lights_reverse_rend = new Renderer[k_];
    29.             lights_position_rend = new Renderer[m_];
    30.             lights_indicator_R_rend = new Renderer[n_];
    31.             lights_indicator_L_rend = new Renderer[r_];
    32.            
    33.         }  
    34.      
    35.     }
    36.  
     
    Last edited: Mar 17, 2018
  21. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
    hello wow this is great. I still have problems with braking. no matter what i set cardynamic overrides the car and the tail breaks out.
     
  22. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    If you mean your settings are overriden this is because there is an script attached at the bottom called "car external configuration" dissable it, it will otherwise override Car Dynamics config with the oen present on the external file.

    I recommend to go trough internals prior to start tweaking ( althow its very tempting :D).
     
  23. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
    hello .no .egal what i set in auto dynamics. car breaks out while braking. i do not use car external configuration
     
  24. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    I dont know. what I know is that simulation breaks when below 50 fps or so. Ais starts to fail etc...

    Otherwise this is a config issue. Suspension etc. This is a complex plugin, you change something there and something else in elsewhere needs tweaking etc. I remember having issues when braking, tweak suspension. sntirolls etc.. You may even whant to search in racing forums to solve your cars behaviours.
     
  25. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
    Thank you . you do a good job
     
  26. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
    sorry again . have problems with the lights,
    which day did you assign which opject?
     
  27. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
    sorry I found the problem. works great
     
  28. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
  29. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
  30. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
  31. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
    unity I restarted. no success
     
  32. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
  33. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
    no. lights tags work,
    have added brake and tires to manuel. then one goes this code in start ()
     
    Last edited: Mar 17, 2018
  34. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    I'm too tired to look into code.
    This is not the proper way to paste code in the forum.
    You'll need to print using debug.log to console and find what is going on by yourself.
    The code I poseted works.
    You need to modfy script execution order as I posted.
     
  35. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    MoDyEnLib.CS

    This script requires modification as is the reason why dll is not properly targeted in teh 64b version

    Switch this:
    Code (CSharp):
    1. [code=CSharp]    #if UNITY_EDITOR_WIN
    2.             #if UNITY_64 || UNITY_EDITOR_64
    3.                 public const string pluginName  =  "MoDyEnPhysics64";  
    4.             #else
    5.                 public const string pluginName  =  "MoDyEnPhysics";  
    6.             #endif
    7.         #else
    8.             public const string pluginName  =  "MoDyEnPhysics";  
    9.         #endif
    [/code]


    by This:

    Code (CSharp):
    1. internal class Sim
    2.     {
    3.         // Unity3D v5 Requires platform dependent plugins.
    4.        
    5.             #if UNITY_64 || UNITY_EDITOR_64
    6.                 public const string pluginName  =  "MoDyEnPhysics64";  
    7.             #else
    8.                 public const string pluginName  =  "MoDyEnPhysics";  
    9.             #endif
     
  36. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
    Hello no problem. was too tired yesterday .hab found the mistake
     
  37. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    GameUI.cs

    The UI as simple as it is is sucking resources like a black hole. Same issue as others, abuse of Update.

    This script is easy to fix

    Remove UpdateUI(); call from Update()

    from Update you'll only whant to call
    During gameplay UpdateCarUI();
    During replay UpdateReplayUI()

    Code (CSharp):
    1.     void Update () {
    2.         UpdateCarUI();
    3.         UpdateReplayUI();
    4.     }
    or

    you could add if (State.isplaying) flag if you whant it not to run during replay.
    And same for State.replay() for second method.

    So Update ui would look like this
    Code (CSharp):
    1.  
    2.     void Update () {
    3.         switch (state)
    4.         {
    5.             case State.Playing:
    6.                  UpdateCarUI();
    7.             break;
    8.             case State.Replay:
    9.                  UpdateReplayUI();
    10.             break;
    11.         }
    12.     }
    13.  
    Then, for every method that represents an event such PaureResume, ShowOptions etc..
    add
    Code (CSharp):
    1.   UpdateUI();
    at the end of each

    And you'll also whan to add on Start a call to
    Code (CSharp):
    1.   UpdateUI();
    This will reduce the hit of 20-30FPS that was taking place.
    I'm also moving from update to fixed update.
    keep in mind as dev already points in the coments tha the f2 telemetry uses OnGui and is RIDICULOUSLY taxing. so dissable it from input script.
     
  38. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    Anyone tested with G27? With G25 Brake and accel are mapped to same pedal and in a quick look I was not able to remap. It was behaving like the new nissan leaf single pedal system. Brake pedal was non responsive.

    EDIT:
    This was not a bug, simply direct input was setup like for an analog joystick. I relized as soon as I saw the code. Simply dissable combined Axis and map brake to RX axis.(for my wheel model).
    Combined axis is also needed for keyboard. At least to teh way inputs are mapped

    Code (CSharp):
    1.  if (combinedAxis)
    2.             {
    3.                 throttle = Mathf.Clamp01(DirectInput.GetFilteredAxis(directInputThrottle));
    4.                 brake = Mathf.Clamp01(-DirectInput.GetFilteredAxis(directInputThrottle));
    5.             }
    6.             else
    7.             {
    8.                 throttle = Mathf.Clamp01(DirectInput.GetFilteredAxis(directInputThrottle, true));
    9.                 brake = Mathf.Clamp01(DirectInput.GetFilteredAxis(directInputBrake, true));
     
    Last edited: Mar 20, 2018
  39. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    604
    Hello people, I see you have noticed the same issue that I am currently dealing with. I dont know what they changed in Unity 5.6.2, but the surface manager is killing the cpu now. In the previous versions I was able to have 64 cars with it in a highly detailed scene with no issues at 60 fps.

    I suspect the Unity Team is strategically targeting my product for some strange reason. Since every time they update, my product gets broken or gets a massive performance hit. This is absolute nonsense, but they even claimed that my project is using Java files a few months back and warned removing the project. They apologised for that, but the strange behaviour from the team is very suspicious and I am about to look forward to Unreal Engine if this absurd action continues. As if they are rivaling with me and constantly changing the internal parts, so that my project would fail.

    In unity 5.5 everything worked perfectly, as soon as I decided to update the project to 5.6.2, they did something, that broke the per texture surface detection method, which had nearly 0-1% of performance hit compared to the insane performance loss that there is now. See for yourself from this old demo:
    https://www.dropbox.com/s/jhz4okd7huuwxlq/cadwell sr3.rar?dl=0

    If I cant get the performance back to this standard, then I will officially abandon this project for unity, and continue on Unreal Engine. Because this is plain insulting, you can clearly see how it was working quite good at decent visuals before 5.6.2.

    This demo was the backbone of revision 2.0 and seems like it was to good for the Unity Dev team, otherwise the current online version should work exactly the same! But straight out of the box, you get 20 fps at the moment.
     
  40. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    Kmon Ravel don´t give up!

    The fixed scripts I posted in here make the project run super smooth already!.

    TBH, IMO, you where doing super taxing stuff in update. But I've to recon that if that was working properly in the past its strange. But usually you wont whan to do the following stuff in update.

    Declare new variables (unless strictly neccesary)
    Run unnecesary loops
    Getcomponent /Getcomponentsinchildren (This is an absolute killer). Use cached variables instead.
    Furthermore, most of the stuff in update does perfectly run in FixedUpdate and while you set project to Vsync others may want to go higher frame rates and most of the methods you had don´t need to run at that high rate.

    I'm sending you modified scripts so you don´t have to go trough all my posts.
     
    carking1996 and user099 like this.
  41. facundogalella

    facundogalella

    Joined:
    Mar 5, 2016
    Posts:
    57
    C'mon, go ahead! this asset sounds like the one realistic car behaviour for Unity
     
  42. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,580
    I agree with TooManySugar.. don't use bad coding practices.. he's fixed a bunch. I really highly doubt they're targeting your project..
     
  43. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    Dev check new incoming Job System that is already available on the Beta, I'm sure you're gonna love it specially for stuff like surface manager in case you whanna go to texture level sure you benefit from it.
     
    Last edited: Mar 28, 2018
  44. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    CarExternalConfiguration.cs

    WARNING

    If you switch to Scripting Runtime Version 4.x equiv load config from file willl fail

    and will do so very badly to the point you'll think project has broken, I switched and forgot about it and took me a while to figure out what was it. I'll check wat is so incompatible. but be warned.
     
  45. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
  46. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    I asume this is IRDS AI controlling the car , never get into depth wonder if the way Ai handles the car could affect. I assume manual handling has same issue.

    To the way the car starts oversteering I would say it's braking and suspension related issue. I would 1) reduce the brake force first 2) modify suspension by 2.1) messing with antiroll bars stiffness 2.2) Other params. I would check racing forums by looking for oversteering issues when braking. I had a somehwat similar issue can´t remember exactly what I did an and atm I'm doing much more art so I can get deep in teh code later on.

    Your frame rate, may be is the video does not seem too fluent. This assets peforms like S*** under 50fps and does perfect at 60 or 60+ fps. If that is part of your issue try firs with the track just with road and terrain collission mesh.

    Also surface manager has a lot of impact in car behaviour so make sure it is configured for road as road etc.

    Report if you fix
     
  47. speedy19802

    speedy19802

    Joined:
    May 10, 2016
    Posts:
    48
  48. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
  49. user099

    user099

    Joined:
    May 29, 2015
    Posts:
    25
    seems the CG calculation is different to the old modyen:

    old:
    centerOfGravtyY = referencePlaneHeight + CGHeight;

    new:
    centerOfMass.y = CGHeight;
     
    TooManySugar likes this.
  50. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    294
    Has anyone here suffered from a weird slow down when using this asset? My FPS stays the same and even when I recorded this issue, the video FPS was constant in my editing program. My FPS will lock at a constant 60 but the gameplay will slowdown. I know the game isn't dropping performance because the car doesn't freak out like it usually does when its running at low fps.

    It happens in the various demos that Ravel has put out for his game, so it's definitely related to this asset. Maybe it's a drive issue?
     
unityunity