Download

Delaying in C++ or workarounds

Ok, so in my project, the editor freezes whenever I get to a spot in my code. I’ve tried debugging uysing strings, but it freezes before the strings print. So, what I do is that I put a debug string and then a delay node in Blueprints. I have narrowed iut down to a C++ function. I need it to wait to run the next line of code until the debug line displays. How can I do this?

You can use Gameplay Timers. You could post the function that causes the freeze as well, maybe we can figure out a better solution.

Did you try debugging using a debugger and not strings? VS Code and IntelliJ Rider for UE4 and VS2019 all have really good debuggers

bool UCraftingLogic::doneCrafting()

{

UE_LOG(LogTemp, Warning, TEXT(“done crafting.”));

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, “done crafting”);

int y = selectedItems.Num();

iter = 0;

UItem* cat;

cat = UItem::createFromRow(selectedRecipe->result,1,baseInv);

for(int x = (y-1); x > -1; x–)

{

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::FromInt(x));

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, “Item to Remove”);

baseInv->removeItem(selectedItems[x]->id,selectedItems[x],1);

selectedItems.RemoveAt(x);

}
This is the function. The names of the variables are dumb, but this is just a prototype. I do not know how to reference databases, in UE4 C++, so in the createfromrow function, I use a row handle.

I think I figured it out. I’ll update here once I’ve eliminated the error, but it has to do with using the spot in the database as the stop in the inventory.

To anyone in the future that finds this: check to make sure that the item in the array you’re asking for actually exists. My error was that I was inputting the database row key as its spot in the array. Now all I have to figure out is if/how object references work when it comes to blueprint.