Hello,
I’ve been trying some thing with unreal and I’m struggling on one.
I wrote a bit of code to make an editor plugin that generates custom actors asset (.uasset).
I have used this tutorial code for instance : https://docs.unrealengine.com/en-US/…art/index.html
I’m saving everything using these lines code:
AMyActor* myActor = NewObject<AMyActor>(Package, ObjectUName, RF_Public | RF_Standalone);
myActor->FloatSpeed = 15.f;
...] Creating a mesh and other things
Package->MarkPackageDirty();
bool bSaved = UPackage::SavePackage(
Package,
myActor,
EObjectFlags::RF_Public | EObjectFlags::RF_Standalone /*| RF_ClassDefaultObject *//*| RF_NeedPostLoadSubobjects*/, saved
*PackageFileName,
GError, nullptr, true, true, SAVE_NoError);
It seems that the export works as I can vizualize my properties values (as you can see below, floatspeed = 15), I can’t load them though.
When I create a new asset from my new file, everything is zero’d (by the constructor it seems ?). I would like to keep my values.
I’ve tried ‘official’ classes : StaticMeshActor for instance, but same here, I can’t make the asset remember its staticMesh ! Same goes if I use a Factory instead of SavePackage.
I guess I have missed something ? Do you have any idea ?
I don’t really catch the use of the OuterPack in your code.
I have tried the AddToRoot() but it doesn’t help here I already had the PostEditChange & Dirty methods too.
But it still initializes to 0. Isn’t it a constructor problem ? (I only have a basic empty constructor)
Your code could work for creating an asset but you don’t modify any UProperty before saving it, do you ?
My asset is successfully created, and I can import it, the problem is the values of my properties that are reinitialized !
Oh ok I see, thanks for your answers.
I now understand the example when we load “/Shapes/shapeName.shapeName” as a mesh
Yet my problem is still here. FloatSpeed still equals to 0 when I create a new actor from my freshly created asset.
I have tried your code too, it does the same for me: creating the asset.
I can see the value by hovering in the contentBrowser but it still doesn’t initialize the UObject with it.
But I still have the same problem. When I drag my new asset in the scene, floatspeed equals 0 !
I’m a little bit surprised to struggle on that as it seems to be quite a basic feature.
I have no idea why you create yet another Actor fron NewObject and then you overwrite the package again with that new object.
There’s no reason to do that:
AMyActor* myActor = NewObject<AMyActor>()
Neither reason to use SavePackage() function.
Also you use GetDefault() while you’re object’s default doesn’t even exist yet because you haven’t used a factory to add any to the created package.