Archive 17/01/2023.

Adding resource dirs during run-time

UnrealDoggie

Hi,
I am wondering if I can add resource dirs during runtime. I am not developing a game but want the
possiblity of creating, saving, loading different scenes during run-time from different directories e.g
SceneA which contains sceneA.xml + accompanying
Models, Materials subdirectories.

ResourceCache* cache = GetSubsystem();
cache->RemoveResourceDir(oldresourcePath);
cache->AddResourceDir(resourcePath);
scene_->LoadXML(…);

Is this way advisable or there will be issues?

Regards,

vmost

Have you tried testing it out? Seems like your only problems would come from trying to access a resource that doesn’t exist.

Modanung

Yes, adding resource folders at run-time is perfectly legitimate.

Also, welcome to the forums! :confetti_ball: :slightly_smiling_face:

JSandusky

If you remove a directory while an async load is in progress that depends on it then obviously nothing is going to continue to load and your log will be packed with error messages. If your resources are “overloaded” (same relative name) then portions of the async load will also be scrambled between the the intended and the “new” resource paths.

Otherwise there shouldn’t be issues.

UnrealDoggie

Thanks for the assurance & ur welcome!

UnrealDoggie

Thanks for ur reply. So would calling
scene_->StopAsyncLoading() eliminate this concern?
As for the “overloaded” part, I guess I will have to manage between different scenes carefully, hence the RemoveResourceDir as I need to deal with 1 scene at a time.
This leads to the question if I made use of urho3d basic models like box, cylinder etc, will the scene just reference urho3d default Models directory?
Thanks.

UnrealDoggie

Hi,
Yes I have. It seems to work but I m a newbie to Urho3d to be sure it is the correct approach. Hence the question.
My first evil way was
engineParameters_[EP_RESOURCE_PATHS] = resourcePath;// +";Data;CoreData";
engine_->InitializeResourceCache(engineParameters_, false);
Well it didnt feel right.

Thanks.

JSandusky

Yes, stopping it will (obviously it halts where ever it is at, but you can change scope of UpdateAsyncLoading and call until progress is complete). Only matters if you do use it though, async load is opt-in.

Assuming you’ve left CoreData and Data as directories then yes.

UnrealDoggie

Good to know. Thanks!