There is always the same crash report no matter how I change this period of code.


 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:

  1. The path you are constructing is invalid (so ClassFinder returns null). You should check that NowClass isn’t nullptr.

  2. 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.


So what path and name should I type?Please tell me,and I’ll be thankful.

1.ConstrutorHelpers一定放在Constructor里,不要放在后面其他的方法中
2.右键Sprite会有Get Reference,点击即可复制,掐头去尾即可使用

非常感谢。

I changed that period of code and now it becomes as following code:



for (int i = 1; i < 9; i++)
{
FString yy = "/Game/Assets/Resources/";
yy.Append(FString::FromInt(i)).Append("_Sprite.").Append(FString::FromInt(i)).Append("_Sprite");
UObject* NowObject = ConstructorHelpers::FObjectFinder<APaperSpriteActor>(yy.GetCharArray().GetData()).Object;
UClass* NowClassA = NowObject->StaticClass();
Classes.Add(NowClassA);
}

But the project still crashed and when I “send and restart”,a message jumped out as following screenshot.
:

在非构造函数加载sprite而不是class的话,用LoadObject更灵活 ,例如LoadObject<UDataTable>(NULL, UTF8_TO_TCHAR(“/Game/DATA/PMV_ATTACK_DEF.PMV_ATTACK_DEF”))

谢了,我现在就去试一试。

Now the program is able to run,but I can’t see the APaperSpriteActor actors,and when I finish it,the warnings jumped out as following screenshots:


So I wonder how I can change the property of mobility.Thanks if someone tells me.

Could someone help me with the newest problem?I’ve searched the data about it on the Internet,but there’s nothing about it.