Describe the bug:
When a raycast intersects with a character entity, the hitResult contains the part that the ray intersected with. For example, if the ray intersected with the player’s head, then hitResult:GetPartName()
would return Head
.
If you call ApplyDamage(0, hitResult, Vector.Zero, entity)
, then print hitResult:GetPartName()
in the OnDamage
entry point on a character script, the part name will be empty.
How do you cause this bug?
I’ve created a reproduction here, with the part names logged to the standard notification log.
If you want to recreate the bug manually, create an object that “shoots” a ray periodically, and call ApplyDamage in the callback.
local ShootScript = {}
ShootScript.Properties = {
{ name = "exitLocator", type = "entity" }
}
function ShootScript:Init()
local start = self.properties.exitLocator:GetPosition()
local stop = start + (self.properties.exitLocator:GetForward() * 1000)
self:Schedule(function()
while true do
Wait(1)
GetWorld():Raycast(start, stop, {}, function(entity, hitResult)
if entity and entity:GetUser() then
entity:GetUser():SendToScripts("AddNotification", FormatString("ApplyDamage: {1}", hitResult:GetPartName()))
end
entity:ApplyDamage(1, hitResult, (entity:GetPosition() - start):Normalize(), self:GetEntity())
end)
end
end)
end
return ShootScript
local BugScript = {}
function BugScript:Init()
end
function BugScript:OnDamage(amt, fromEntity, hitResult)
self:GetEntity():GetUser():SendToScripts("AddNotification", FormatString("OnDamage: {1}", hitResult:GetPartName()))
end
return BugScript
Your Crayta username: Cereal
Game seen in (including “Hub” or “Editor for XYZ”): Crayta
How regularly do you see this? (E.g. 2/3 times - please try 3 times if possible): Every time
Time + date seen: March 09 2022
Version number (found in Help tab in Settings): 0.e5.40.115857