for (int i = 1; i < 9; i++)
{
FString yy = FPaths::GameDir();
yy.Append("Content/Assets/Resources/").Append(FString::FromInt(i)).Append("_Sprite.").Append("Paper2DSprite_C");
UClass* NowClass = ConstructorHelpers::FClassFinder<APaperSpriteActor>(yy.GetCharArray().GetData()).Class;
TSubclassOf<APaperSpriteActor>NowClassA = NowClass;
Classes.Add(NowClassA);
}
I’m trapped here for several days and have been searching useful data on the Internet till now.Who can tell me how to solve the problem?I’ll appreciate it if anyone helps me.
You should probably post the problem you’re getting and what you’re trying to do. I assume you’re trying to reference 9 sprites and add them all to a class array (which really doesn’t make sense)?
So, here’s where you can be going wrong:
The path you are constructing is invalid (so ClassFinder returns null). You should check that NowClass isn’t nullptr.
You can use Cast<APaperSpriteActor> instead of TSubclassOf to do your casting.
Also it should be noted that you are loading CLASSES here and not OBJECTS. So, unless you have 9 different classes that all inherit from Paper2DSprite_C and plan to instance them later - I’m not sure what you’re going for.
I just wonder how I can write down the right path and **the right file name.**I create 8 different classes and want them to be the classes of the sprites in the following screenshot.I only know that if I pull the sprites into the scene,they’ll be APaperSpriteActors.