UE4 C++: EXTENDING ENGINE CLASSES/STRUCTS USING PLUGIN

Hello! I’ve been implementing functions and systems utilizing Serialization, but I’ve found that some Classes/Structs have variables under protected, so I can’t access the information I need for my system to work. One of the structs is FSlateColor, which I need to access the Tint SpecifiedColor and the ColorUseRule but it’s protected. I know one of the solutions is modifying the source engine code and expose the variables to public, but I want to be able to make this change only by installing my plugin, without actually touching the engine source itself. How could I do this for Structs and Classes? Thanks!

Dear valued Unreal Engine user,

This really depends on the specific class and how it is used elsewhere in the engine. Some classes you may be able to use C++ inheritance and create a subclass that overrides the base class. If, however, that class/struct is passed around by value and not reference or pointer at any point, then this may not be a straight forward solution.

In that case you may be able to create a sub/derived class that took the base class as a copy constructor, then only in the places you need to access the new functions you instantiate the derived class on the stack.

For anything that is a UPROPERTY you may be able to access it via reflection in C++:

Specifically related to serializing UObjects and UStruts, it may also be that you can just pass some of those to an FArchive by <> and it will iterate though and serialize all of the UPROPERTY members directly.

In the case of FSlateColor it looks as though you should be able to call GetSpecifiedColor(). In the case of ColorUseRule you may be able to infer what it is from the result of SlateColor.IsColorSpecified() and comparing SlateColor.GetColor(InWidgetStyle) to InWidgetStyle.GetForegroundColor(), and so on. Though that would not be performant compared to just returning the ColorUseRule. In most use cases it would seem that the intention is to just use GetColor and if you are trying to something outside of that, you may want to double check the use-case.

Thank you for your continued support,

Thanks for your input! So basically I could create a subclass deriving from the class I want to modify, then modify the subclass, and use that to replace the class? But how would I replace it using a plugin? How about for other structs that have variables I need that aren’t exposed?

So, I’ve made a class deriving from UBackgroundBlurSlot. But how do I replace UBackgroundBlurSlot? I’ve tried +ActiveClassRedirect but I get a crash and an error. Also, should I add the directory to the name? For example: “/Script/MyModule/AFolder.ChildClass”. Please respond as soon as you can! Thanks!

LOG

The reason behind why I wanted to use this was to access the value of a protected variable. But instead of going through all this hassle to replace the existing class with my own, I used FindFProperty() to get the property of the variable and get/set the value from there.