x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Why does a function's local variable of type AssetID resolves to None?

Hello, While trying to understand the AssetID variable type, I stumbled upon a problem that I don't get.

I have a custom DataAsset called MyDataAsset created in code:

 UCLASS(BlueprintType)
 class ASSETIDTEST_API UMyDataAsset : public UDataAsset
 {
     GENERATED_BODY()
 public:
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Data Asset")
     FString String;
 };

Then I created an asset called NewDataAsset of type MyDataAsset: alt text

Then I creat an Actor with a NewDataAsset variable of type AssetID, and a function that prints the String value: alt textalt text

But if I use instead a local variable, the Resolve AssetID node resturns None: alt textalt text

Why is this happening? I can't create objects using an AssetID with local variables?

Product Version: UE 4.9
Tags:
captura4.jpg (50.3 kB)
captura2.jpg (23.8 kB)
captura.jpg (47.9 kB)
captura3.jpg (20.8 kB)
captura1.jpg (45.5 kB)
more ▼

asked Sep 10 '15 at 07:16 PM in Using UE4

avatar image

Ghar
682 33 107 127

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hey,

The idea of Asset ID is to keep weak reference to an asset on your hard disk it can be anything!, It is I think C++ equivalent of FStringAssetReference/TAssetPtr ( look : HERE ).

To give you a bit of an outline as to why it is so important. Think about a scenario where you have references to say e.g 1000 textures on hard disk, it will stall your main thread if you try and load 1000 textures into memory all at once on game thread, you should avoid this and always show some kind of throbber or wait symbol whilst loading a large asset ( can be anything ).

So to answer your question, a better way to do it would be to do an async/non blocking load which notifies you via delegate callback once the asset is done loading. See image below which takes AssetID as input parameter and triggers output once asset is done loaded with loaded asset pointer.

Use that function to fire off an async load and then use the output object and it should not be None anymore. Hope this helps

Thank you.

alt text

capture.png (18.6 kB)
more ▼

answered Sep 21 '15 at 01:15 PM

avatar image

Gam3r
16 2 7 6

avatar image Ghar Sep 21 '15 at 03:03 PM

Ohh I see. Thank you, it is very useful information !

The LoadAsset node is not available inside functions thought. And I just realized that the Local AssetID Variable loses it's default value:

alt text

Maybe it doesn't make sense to use AssetID type variable as local variables inside functions?

avatar image Gam3r Sep 21 '15 at 03:36 PM

LoadAsset node is global you should be able to use it where ever necessary. And yes you should keep AssetID under class scope not within function scope as it will get garbage collected once the function goes out of scope

avatar image VictorRachels Oct 28 '16 at 01:34 AM

Functions can't use Latent operations (functions that may take some time, then call back - note the little clock in the top right of the node). Use an event to do the actual LoadAsset process, then call another function or event to handle the loaded asset when the LoadAsset 'Completed' pin is executed.

Local Variables are 'recreated' each time a function is called. Use the full blueprint scope variables ('variable' without the 'local') if you need the content to be retained for the future. If you need multiples, use an array.

avatar image Gam3r Sep 21 '15 at 03:40 PM

I just did a test case, by creating a data table with a structure and use

 UPROPERTY(Category = WheelSetData, EditDefaultsOnly)
 TAssetPtr<UStaticMesh> RightMesh;

And when I did get row and called load asset it did an async load for that mesh and did a call back. Image belowalt text

capture.png (91.6 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question