Page 1 of 1

[2.0.55] Teleporting car to other surface invalidates reference to non-player driver

Posted: Thu Jun 19, 2025 10:02 am
by robot256
What did you do?
1. Place a non-player character entity inside a car.
2. Store a LuaEntity reference to the non-player character entity.
3. Used a script to teleport the car to another surface.

To replicate, load the attached save and run the following command:

Code: Select all

/c game.print("Before teleport, storage.driver.valid="..tostring(storage.driver.valid)); storage.vehicle.teleport({0,0},"surface2"); game.print("After teleport, storage.driver.valid="..tostring(storage.driver.valid).." and storage.vehicle.get_driver().valid="..tostring(storage.vehicle.get_driver().valid))
What happened?
The stored LuaEntity reference is now invalid even though the same non-player character entity still exists in the car.
What did you expect to happen instead?
I expected the stored LuaEntity reference to remain valid, since the entity it references still exists.
Does it happen always, once, or sometimes?
Always. Note that Lua references to player-controlled characters do remain valid when teleported.
Context:
This bug manifests when Vehicle Wagon 2 attempts to teleport an AAI Programmable Vehicles "AI Car" to the hidden storage surface. When it does this, the LuaEntity reference that AAI stores to the non-player AI driver character driving the car becomes invalid even though the AI driver character still exists in the car (same unit_number), and AAI creates a new (second) AI driver character.

If this is intentional, then it would be nice to mention it in the documentation for LuaEntity::teleport().

Re: [2.0.55] Teleporting car to other surface invalidates reference to non-player driver

Posted: Mon Jun 23, 2025 6:56 pm
by Rseding91
Thanks for the report. This is now fixed for the next release.

Re: [2.0.55] Teleporting car to other surface invalidates reference to non-player driver

Posted: Tue Jun 24, 2025 2:21 am
by robot256
Thank you!