Failing to save Static Mesh after adding sockets with Editor Utility Widget

Hi, I made a simple Editor Utility Widget that copies sockets from one mesh asset to another. It seem to work fine but modified mesh fails to save. Does anybody know why? I am on version 5.6.1.
Thank you for your time :slight_smile:

Hey @Lokstrel how are you?

It seems the problem is it doesn’t automatically mark the asset as “dirty” (modified/unsaved), so the changes won’t be saved and won’t even show up in the list of files to save. The sockets are being added in memory correctly, but UE doesn’t know it needs to save the changes.

To solve this, you can try by adding two nodes to your blueprint: “Begin Transaction” and “End Transaction”.

The first one should be added bewtween your “On Clicked” and the first “Get”. And the second one needs to be connected to the “Completed” pin of your For Each Loop.

You don’t need to add any value to the “Begin Transaction” node, but you could add your mesh to its “Primary Object” anyways.

Hope this helps you! Let me know if you need more help!

Hello, thank you for your answer. I hope you are having a nice day.

I added Begin Transaction and End Transaction nodes but the problem persists. Problem is not that Unreal does not try to save the asset, but it throws error when saving it (I probably should specified that in original post, sorry).

Here is the error message that I get:

When I add Sockets manually, asset saves without problems.

Hello again @Lokstrel !

Ohh ok ok, then it’s a completely different thing! haha

Could you share your log when you get that error? As that pop-up doesn’t say anything really useful. Go to “Window” - “Output Log” and seach for the lines in red that appears when you click on “retry”, and post them here!

I’ll be waiting for your answer!

I didn’t find any red text in output log, but I found several warnings mentioning assets that I tried to save:

LogSavePackage: Warning: Referencers of StaticMeshSocket /Game/0_created_By_Me/General_Meshes/Pillar_01.Pillar_01:StaticMeshSocket_0:
LogSavePackage: Warning: StaticMesh /Game/0_created_By_Me/General_Meshes/Pillar_01.Pillar_01 (1 refs)
LogSavePackage: Warning: 0) ObjectProperty /Script/Engine.StaticMesh:Sockets.Sockets
LogSavePackage: Warning: StaticMesh /Game/0_created_By_Me/General_Meshes/Pillar_02.Pillar_02 (1 refs)
LogSavePackage: Warning: 0) ObjectProperty /Script/Engine.StaticMesh:Sockets.Sockets
Warning: Can’t save ‘../../../../Unreal Projects/Arena_Game/Content/0_created_By_Me/General_Meshes/Pillar_02.uasset’: Illegal reference to private object: ‘StaticMeshSocket /Game/0_created_By_Me/General_Meshes/Pillar_01.Pillar_01:StaticMeshSocket_0’ referenced by ‘Pillar_02’ (at ‘/Game/0_created_By_Me/General_Meshes/Pillar_02’) in its ‘Sockets’ property.

Hope it helps.

Hello again!

I’ve been trying to solve this issue and I did it! The only caviat is that you will need to implement some C++ code to be able to do it, but lets start with the blueprints part first!

Your approach is mostly correct! The only problem with it is that you are assigning a reference to a socket that belongs to a different “package” (your first static mesh) instead of creating a new socket. So we will change some parts of the bleuprint first.

  1. The first part, until the for each loop included, will be exactly the same!
  2. In the loop, instead of adding the socket to the new mesh, you will need to duplicate the socket:
  3. immediately after that, you will need to add the node “Begin Transaction” with your target mesh as its “primary object”:

    This node will tell that asset that it has been modified (mark it as “dirty”), so the engine will let you know you need to save it.
  4. The next step is the one that needs a C++ implementation to work, as you CANNOT cast to “Static Mesh Socket” natively in Unreal Engine. But first let me show the complete blueprint:

    The green node is a custom function you will need to create using C++, and “End Transaction” is to close the transaction you started in the previous step. As you can see, you are adding the new Socket to your Mesh, instead of adding a reference to your first mesh’s socket.

And that’s it for the BP. Lets do the C++ part!

  1. First of all, you need to go to “tools” in your Engine window and click on “New C++ Class…”:
  2. On the next window, click on “All Classes” and search for “BlueprintFunctionLibrary”, then click on “Next”:
  3. Name your function library something like “SocketCopyFunctionLibrary” and you will see it will create a “source” folder in your project if you don’t have it already. Click on “create class”:

    After that, you will get some warnings. Click “ok”, then click “no”, and close the engine.
  4. Now, in your project folder, you will see a new file with “.sln” extension. You need to open it with Visual Studio or any IDE you like.
  5. Navigate your project until you can open both new files (In my case, both of them are called SocketCopyFunctionLibrary.h and SocketCopyFunctionLibrary.cpp). This is how it looks in my Visual Studio:
  6. In your “.h” paste this:
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "SocketCopyFunctionLibrary.generated.h"

class UStaticMeshSocket;

/**
 * 
 */
UCLASS()
class ANIMATIONSHARING573_API USocketCopyFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
public:
	UFUNCTION(BlueprintCallable, BlueprintPure)
	static UStaticMeshSocket* CastToStaticMeshSocket(UObject* Object);
	
};
  1. Then paste this in your “.cpp”:
// Fill out your copyright notice in the Description page of Project Settings.


#include "SocketCopyFunctionLibrary.h"
#include "Engine/StaticMeshSocket.h"

UStaticMeshSocket* USocketCopyFunctionLibrary::CastToStaticMeshSocket(UObject* Object)
{
	return Cast<UStaticMeshSocket>(Object);
}
  1. The final step is to compile the project! To do it with Visual Studio, make sure you have “Development” selected and then click on play “Local Windows Debugger”. This will compile and open the editor again:

After doing that, you will be able to use the green node “Cast to Static Mesh Socket” in your blueprint and your Editor Utility will create copies of all the required sockets, then it will add them to the new mesh!

Once you do this, you will be able to open the project from the launcher or .uproject file as you always do, as you don’t need to compile more C++ code.

Hope this helps you! Let me know if you need more help!

It Works! Thank you so much!
That detailed guide really helped. I couldn’t do it without it.