OnAssetPathChanged returns invalid FString

When using the ContentBrowser callback OnAssetPathChanged(), an invalid FString will be passed if the user clicks on the breadcrumb navigation rather than the tree navigation. A proper FString is passed if the user clicks on the tree navigation.

Hey -

I’m not sure how you’re using OnAssetPathChanged(). I’m also not sure what you mean when you refer to “breadcrumb navigation”, do you mean the folder names next to “Save All” in the content browser? When I click on the folder names here it simply switches to that folder in the CB. Can you elaborate on what exactly you’re seeing when the bug happend? Are you able to reproduce this issue in a clean project with no additional content? If so can you list the steps that produce the bug?

I am referring to the navigation area directly above the thumbnails in the content. Here I have highlighted it on a screenshot.

I am simply subscribing to the content browser’s OnAssetPathChanged delgate. See this thread:

The forum post mentions having a class derived from UObject. What does this class look like? Can you explain how your project is setup so that I can try testing this on my end?

Unfortunately due to MPAA restrictions I am unable to copy and paste code online.

But the class is basically just a shell. It derives directly from UObject and implements only one method for the delegate and has one property, an FString in which it stores the path each time the delegate is called. It is just one hugely ugly work around for the fact that the Content Browser can’t be directly asked to give the current path.

The delegate is

void OnAssetPathChanged(const FString& newPath)
As defined here: FOnAssetPathChanged | Unreal Engine Documentation

It is being registered with the Content Browser module when my plugin starts up in the StartupModule() method. In the code below “BrowserTracker” is my shell class.

FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked(“ContentBrowser”);
ContentBrowserModule.GetOnAssetPathChanged().AddUObject(BrowserTracker, &UBrowserTracker::OnAssetPathChanged);

Now this works perfectly fine if the user changes paths by clicking in the standard tree view on the left of the Content Browser. A proper FString is sent and the BrowserTracker class saves that for future reference when needed. But if the user navigates instead by clicking on the folder names in the breadcrumb bar, the FString sent to the delegate is not valid.

EDIT: I have been tracking the issue down a bit, and from what I can tell the value is correct at the time of the SBreadCrumbTrail::CrumbButtonClicked(). In that function it then calls the delegates in the line OnCrumbClicked.ExecuteIfBound(CrumbList.Last().CrumbData); At that point CrumbData is storing the proper path (“/Game” in my test), but the next call in the stack that value suddenly is shown as “Invalid” in the debugger, and remains invalid all the way to my delegate.

It isn’t a matter of share publicly or privately, it is a matter of production machines are physically not connected to the internet :slight_smile: It is impossible to share anything.

The above should be able to help you, but I will see if maybe I can build a new sample project at home during the holidays.

I understand that you can’t share the code publicly. Could you create a sample project with the error occurring that you could provide and/or provide clear reproduction steps that I can follow to setup a project to test myself? Without either of these I’m not certain I reproduce enough to enter an effective report.

If you are using MSVC you could try using the memory window to look at the address of the string variable… This won’t solve your problem, but may make it immediately obvious what is going on. Sounds suspiciously like something is being optimized out so the debugger can’t see it - are you on the ‘DebugGame’ build target?

The only other tactic I can think of is logging the string both before and after the delegate fires

I am on DebugEditor. VC has a different notation for optimized variables though.

If by log you mean print to the console, well accessing the FString causes a crash :slight_smile:

So you are copying the passed string to a new variable and not referencing a const FString& variable that goes out of scope as soon as the delegate has fired?

Code should look something like:
FString NewStringVar = FString::Printf(“%s”, *StringPassedInByDelegate);

Other than that, not sure on holiday away from so can’t test anything…

Could conceivably be an engine bug that mangles the null terminator of the string in very specific circumstances (memory view will show you this).

Hey -

I was wondering if you had had the chance to put together a sample project with this issue occurring? Was psychogony’s last comment able to help at all? If you are getting a crash can you post the callstack and log files from the crash to provide additional information

Hi,

The crash you mention has since been fixed, I believe for 4.10, but certainly for 4.11.

I will point out that OnAssetPathChanged is called for any Content Browsers that are open, so if you’re relying on it to track the path of the current Content Browser, then you may be in for a surprise.

Depending on what you’re using it for, there may be better options available. Are you able to explain any more about what you’re trying to do?

Thanks,
Jamie.

Hi Jamie,

We have custom import tools that provide the link to our pipeline for importing assets into Unreal. For various complicated reasons we can’t just use the standard Import or import hooks that may be available. Instead we have a button in the toolbar that when clicked opens up a dialog allowing the artist to select assets from our pipeline, and then we import those. When we import them we want to of course import them into the proper folder for the artist. However we were unable to find any way to query the current folder, so instead wrote this simple tracker to watch for changes and save the path changed to. This provides us with the ability to on demand return the current folder.

Does that make sense?

Hi ,

I do have a sample project that illustrates the issue, though with Jamie’s reply below it sounds like you guys got it already? If you want to be sure, I can still send the project in to you if you give me an email address.