1. Trouble with the game?
    Try the troubleshooter!

    Dismiss Notice
  2. Issues with the game?
    Check the Known Issues list before reporting!

    Dismiss Notice
  3. Before reporting issues or bugs, please check the up-to-date Bug Reporting Thread for the current version.
    0.30 Bug Reporting thread
    Solutions and more information may already be available.

Vehicle Lua mapmgr.objects is not consistent with actual objects in scene

Discussion in 'Troubleshooting: Bugs, Questions and Support' started by angelo234, Apr 5, 2021.

  1. angelo234

    angelo234
    Expand Collapse
    Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    540
    • After the first vehicle spawns in the map, mapmgr.objects is still empty and it only updates after a second vehicle is added
    • When removing other vehicles from a vehicle, mapmgr.objects still shows the list of vehicles before removal
    --- Post updated ---
    Alright so I found the problem and found a fix. So in the file "BeamNG.drive\lua\ge\map.lua", the function "updateGFX" at line 1219 will only call mapmgr.objectData function (which updates mapmgr.objects) when there is more than one vehicle in the map (at least one vehicle without a player). This is because the for loop iterates through all vehicles in the map and "o.active" represents whether a player is in the vehicle or not. And so if "o.active" is false (player not in the current vehicle) for the vehicle of the current iteration, then it will update. So it makes sense that when you spawn the first vehicle, mapmgr.objects will not get updated since there is no vehicle without a player (only your vehicle exists). And it makes sense that when you remove other vehicles, it won't get updated since there is no vehicle without a player after removing other vehicles.

    So the fix is to change the code of the "updateGFX" function in the file "BeamNG.drive\lua\ge\map.lua" at line 1219 from

    Code:
    local function updateGFX(dtReal)
      for _, o in pairs(M.objects) do
        if o.active == false then
          be:queueAllObjectLua('mapmgr.objectData(' .. serialize(M.objects) .. ')')
          break
        end
      end
    
      objectsReset = true
    
      delayedLoad:update(dtReal)
    end
    to

    Code:
    local function updateGFX(dtReal)
      be:queueAllObjectLua('mapmgr.objectData(' .. serialize(M.objects) .. ')')
    
      objectsReset = true
    
      delayedLoad:update(dtReal)
    end
     
    • Like Like x 2
  2. retrospek

    retrospek
    Expand Collapse
    BeamNG Team

    Joined:
    Feb 23, 2016
    Messages:
    19
    You are absolutely right. Thank you for looking into this! :)
     
    • Like Like x 1
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice