Announcement

Collapse
No announcement yet.

"Newobject" Appears after deletion C++

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    "Newobject" Appears after deletion C++

    Hi,
    For the needs of a project, I created a code in C ++ that allows me to create a datatable from a button in an Editor Utility Widget.
    In fact I created a node in c ++ linked to my Button like this:


    Node Create My DataTable

    After entering a name in the text field and clicking on the create button everything is going well and I have a new folder with my New Datatable inside.
    So far everything is going well…
    The problem occurs when I delete the datatable ; this one seems to be deleted, but when I leave the folder then I come back in, the datatable is again present !

    Here is a video of the process:


    You should know that I am a c ++ noob and that the code I created is the result of extensive research on the internet. So I don't know at all how to correct my problem.
    If anyone can help me correct my code, I would be very grateful.

    PS : Sorry for my english, hope you will understand me.


    Here is my code:

    .h
    Code:
    UCLASS()
    class LOCKLEVELCPP_API UCreateDataTable : public UBlueprintFunctionLibrary
    {
    GENERATED_BODY()
    
    public:
    
    UFUNCTION(BlueprintCallable, Category = "My Nodes", meta = (DisplayName = "Create My Data Table", Keywords = "Create My Data Table"))
    static void CreateDataTable(FString Name);
    };
    .cpp
    Code:
    void UCreateDataTable::CreateDataTable(FString Name)
    {
    FString Named = Name;
    
    FString PackageName = TEXT("/Game/DataTableCreated/");
    PackageName += Named;
    UPackage* Package = CreatePackage(NULL, *PackageName);
    Package->FullyLoad();
    
    UDataTable* TestObj = NewObject<UDataTable>(Package, *Named, RF_Standalone | RF_Public | RF_MarkAsRootSet);
    TestObj->RowStruct = FDialogStruct::StaticStruct();
    
    TestObj->AddToRoot();
    Package->MarkPackageDirty();
    FAssetRegistryModule::AssetCreated(TestObj);
    
    FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension());
    bool bSaved = UPackage::SavePackage(Package, TestObj, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, *PackageFileName, GError, nullptr, true, true, SAVE_NoError);
    }

Working...
X