Need help getting a TAssetPtr asset loaded in game, getting crashes

I’m working on a little card game project and this thing has like 550 cards for the most basic version and many more to add on top of that, so I decided I wanted to load my assets in C++ and expose them to blueprint as arrays where I can work them easily. I found and followed this tutorial the best I can (Asynchronous Asset Loading | Unreal Engine Documentation). I’m coming from a Java background and still learning C++ and that guide was a bit advanced for me, but I managed to kind of get what I wanted. I am able to search my card folder and create an array of TAssetPtr and expose them to blueprint. I can see on my blueprint, in the options, my 2 texture arrays are there and I can expand them and see all the textures as I would expect. Ok, so all good so far.I threw together a little loop in blueprint to spawn all the cards in an array so I could apply all the textures from the array as a good test to verify it works. I have a material instance setup and a texture sample set as a parameter and I can manually make an array in blueprint of textures and it seems to work fine. The chain that spawns the cards happens on game start, in the level blueprint I fire a custom event on the card table blueprint which spawns the test cards.

Heres a screenshot that shows the code, the blueprint, and and it running in game.

Next is where the problem comes in. When I plug in the texture sample from the array I built in code, the editor crashes with an unhandled exception. I am guessing it isn’t properly loaded or something, even though it does show up in the editor (just in the properties panel) and in blueprint. It doesn’t matter if I plug in the Array Element from the ForEachLoop into the Set Texture Parameter Value or if I plug in the little get index 0 of array node I have there, I still get the same crash. I tried plugging in an array get of index 0 in just to see if even one texture would work.

Heres a screenshot that shows the initial crash when I hit the simulate button if I have my UTexture2D array plugged in:

Heres a screenshot that shows just visual studio after I hit the Break button, it almost seems like whatever module is needed to show me a useful error isn’t loaded or something.

Also heres a code snippit of my declarations, maybe something needs to change here?

	UObjectLibrary* blackCardLibrary;
	UObjectLibrary* whiteCardLibrary;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Cards)
	TArray<TAssetPtr<UTexture2D>> blackCards;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Cards)
	TArray<TAssetPtr<UTexture2D>> whiteCards;

	UFUNCTION(BlueprintCallable, Category = CardLoading)
	void LoadCards();

I’ve been trying different things and googling around for answers, but I’m as a loss as to what to try next to get these textures loaded in game. It seems like they are working perfectly until I hit the play / simulate button and try to load them in game on a dynamic material instance.

How can I stop it from crashing? Am I approaching this correctly?, Is there something else I need to do when loading my assets?

Thanks.

causes problems, you should put a space between the angle brackets:

TArray<TAssetPtr<UTexture2D> >

Thanks. I added the spaces and tried it and I got the same crash. I’ll keep that tip in mind though when I am doing the double angle brackets.

in the example, they check if (!ObjectLibrary) exists before creating the library and adding to root, so maybe this is happening multiple times?

maybe forget about loading 2 decks at once and just get 1 of them working first.

also since PDB files are mentioned in the error message, and they are a debugging thing, why not try compiling in Development Editor and seeing if you get the same crash.

https://docs.unrealengine.com/latest/INT/Programming/UnrealBuildSystem/Configuration/index.html
“If you encounter weird “RPC” or “PDB” link errors, then you should set bUseIncrementalLinking=false in ValidateConfiguration()”

or maybe arrays of TAssetPtr just don’t work with blueprint. maybe try accessing it in c++ instead…

Thanks for the suggestions! First I tried the first few things in your suggestions. I added the if (!ObjectLibrary) check and commented out all of one deck of cards so I could concentrate one one. Visual studio was already set to Development mode so I tried some of the other mods and I checked the BuildConfiguration.xml file (I guess the documentation must be out of date, that mentions a .cs file) but I found the bUseIncrementalLinking boolean and it was already set to false. So after all that, still the same crash. So I went ahead with your last suggestion.

I tried to do it as simple as possible to figure if it would work and it does! It seems to work no problem. All I did was make a function to take the material instance I created in blueprint and the array index then just apply the texture from code using the arrays I already have setup and it seems to work.

I declared this:

UFUNCTION(BlueprintCallable, Category = CardLoading)

void setCardTextureParameter(int32 index, UMaterialInstanceDynamic* material);

then just added this super simple function:

void ACAHTable::setCardTextureParameter(int32 index, UMaterialInstanceDynamic* material)
{
	material->SetTextureParameterValue(TEXT("CardFace"), blackCards[index].Get());
}

Thanks, that is all I really need, I can totally work with this. I’ll probably migrate more of the stuff from blueprint to code, but yeah, I’m happy now.

sweet, im glad it works :slight_smile: it seems that most blueprint problems can be fixed by switching to c++, especially anything dealing with arrays and structs.