How do I create a *temporary* UCurveFloat?
So I've got a variety of curves that are stored as FRichCurves in my own UDataAsset that I want to show in an editor plugin. This requires creating temporary UCurveFloat* objects with no physical counterparts in the content browser (there's about 500 curves, which would stink up the content browser and require a lot more lookups) because SCurveEditor only takes those.
My question is, what can I do to make UE stop apparently auto-garbage collecting parts of them at inopportune times? When the editor tries to autosave, I get... this result, which isn't very useful. I can't make it a safer reference-counted pointer, because apparently you cannot do that with an UObject. If nobody has any suggestions, I guess I could write my own FRichFloat editor, but I was really hoping I could stick to the built-in stuff. I mean, that's what it's for, right?
(also, you know, you might want to sanity check the data at that point in SCurveEditor.cpp anyway, since apparently it can sometimes be null)
You can use AddToRoot() to temporarily mark an object as part of the root set (and thus safe from garbage collection) while you are editing it. Call RemoveFromRoot() when you are finished with your temporary object and want to allow it to die.
If the outer calling code is itself in a UObject then you just need to store a reference to your temporary object in a UPROPERTY() so it can be found during GC.
Finally you can also use a FGCObject class to keep something alive, but one of the first two approaches are probably better.
Cheers, Michael Noland
answered Jan 13 '17 at 11:11 PM
Michael Noland STAFF
Follow this question
Once you sign in you will be able to subscribe for any updates here