When I try to cast my c++ actor class to it’s blueprint class, it fails. I’m not sure why since the blueprint class was created from the c++ class.
The createItem function spawns a new Aitem and returns its pointer. In blueprints, I then attempt to cast it but it always fails : image
.Aitem* ADungeonLevel::createItem(FName iname)
{
Aitem *newitem = NULL;
FVector location(500.f, 500.f, 500.f);
FRotator rotation(0.f, 0.f, 0.f);
FActorSpawnParameters spawninfo;
spawninfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
for (int i = 0; i < ItemsPtr->AllItems.Max(); i++)
{
for (int n = 0; n < ItemsPtr->AllItems[i].Items.Max(); n++)
{
if (ItemsPtr->AllItems[i].Items[n].EditorName == iname)
{
newitem = GetWorld()->SpawnActor<Aitem>(location, rotation, spawninfo);
// set item data
newitem->setItemData(ItemsPtr->AllItems[i].Items[n]);
break;
}
}
if (newitem) break;
}
if(!newitem) UE_LOG(LogItem, Error, TEXT("Error creating new item") );
return newitem;
}