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.