Enabling Attached Object Collision

From Onset Developer Wiki
Revision as of 16:20, 24 January 2020 by BlueMountains (talk | contribs) (Created page with "SetObjectAttached disables the collision of some objects. Here is how to enable collision. server.lua: <syntaxhighlight lang="Lua"> --- Set this property value to your attach...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

SetObjectAttached disables the collision of some objects. Here is how to enable collision.

server.lua:

--- Set this property value to your attached object:
SetObjectPropertyValue(o, "_enableCollision", true)

client.lua:

AddEvent("OnObjectStreamIn", function(object)

    local _enableCollision = GetObjectPropertyValue(object, "_enableCollision")
    
    if _enableCollision == true then
        
        -- We need to delay enabling the collision. Attached objects have their collision set in the attach RPC that comes after the stream event.
        Delay(200, function(object)
            if IsValidObject(object) then
                GetObjectActor(object):SetActorEnableCollision(true)
                local SMC = GetObjectStaticMeshComponent(object)
                SMC:SetMobility(EComponentMobility.Movable)
                SMC:SetCollisionEnabled(ECollisionEnabled.QueryAndPhysics)
                print("Enabled collision")
            end
        end, object)
        
    end
    
end)