Update stream folder at runtime

Let’s say I have exported a custom ydr to the stream folder, and I run the server and join. I now update the ydr, replace it, and restart the resource. From my experience doing this, the ydr is not updated. Is this even possible? Is there some way I can force a reload of streamed assets on the client-side without having to rejoin the server?

This is the code I have now to spawn in the object. I delete it when the resource stops

local MODEL_NAME = 'light_test'
local HASH = GetHashKey(MODEL_NAME)
local currentEntity = nil

RegisterCommand("s", function()
    print('Requesting...')
    RequestModel(HASH)
    
    CreateThread(function()
        while HasModelLoaded(HASH) == false do 
            Wait(0) 
        end
    end)
    
    currentEntity = CreateObject(HASH, LIGHT_POS[1], LIGHT_POS[2], LIGHT_POS[3], false, false, false)
    SetEntityAsMissionEntity(entity)
end)
  
AddEventHandler('onResourceStop', function(name)
    if name == 'lighttest' and currentEntity then
        DeleteEntity(currentEntity)
    end
    SetModelAsNoLongerNeeded(HASH)
end)

Hey FColt84,
you can force reload streamed assets and resource metadata by executing the “refresh” command.

I’ve tried this and it does not work. If you were to add a new asset into stream and refresh it would work, but it does not work if you update an asset, which likely has to do with the asset being cached on the client. If the client rejoins the server, the assets is updated without the server having to be restarted so this is clearly the case. The question now is, how can I make the client use the new version of the asset from the server without rejoining? I’ve looked at using RegisterResourceAsset and RegisterStreamingFileFromCache and had no success. Even RegisterStreamingFileFromUrl did not work. Here is how I attempted to do so:

client.lua

RegisterNetEvent("getCacheStr")
AddEventHandler("getCacheStr", function(cache_str)
    h = RegisterStreamingFileFromCache('lighttest', 'light_test.ydr', cache_str)
    print(h) -- Prints out a hash each time. I'd assume it returns 0 on failure?
end)

TriggerServerEvent("getCacheStr")

server.lua

AddEventHandler("getCacheStr", function() 
    local cache_str = RegisterResourceAsset('lighttest', 'stream/light_test.ydr')
    TriggerClientEvent("getCacheStr", -1, cache_str)
end)

And for the URL function I have tried:

client.lua

h = RegisterStreamingFileFromUrl('light_test.ydr', URL)
print(h) -- Again, prints out a hash

Another thing to note is if I update a streamed asset and restart the resource without deleting that asset, the client crashes. As you can see in my script I make sure to delete the entity and remove the model from memory when the resource stopped.

Try running str_requestFlush in the client console (requires dev mode) after stopping the resource.

1 Like

That worked, thanks! :slight_smile: Is there any way to run that command programmatically? I tried using ExecuteCommand('str_requestFlush') but that didn’t do anything.

EDIT
Didn’t realize that it outputs “access denied” when I try to execute the command using ExecuteCommand()

I have tried running add_ace resource.lighttest command.str_requestFlush allow and add_ace builtin.everyone command.str_requestFlush allow but still get “access denied”.

I don’t think the client console has any permission-adding implemented at this point., nor is there any other way to directly call it from script (or should one on e.g. a server with more than one player around).

Ok, no big deal. Thanks for the help.