Changing UPROPERTY type based on other UPROPERTY

Is it possible to do with some C++ magic?

Fir example I have to variables, both declared in C++ base class.

First store the Object Class and is set up from subclassed blueprint. Second is instance Variable and it’s type should change to the value set in firs variable, or be Object if null.

Is that kind of magic possible in C++? Have anybody did something like that? Maybe some tweaking of Class properties can be implemented at runtime?
That is expected to be some kind of template mechanism.

Templates wont do anything for you, since they evaluate at compile time, and you are looking to do stuff at runtime.

Do you want the variable to be of arbritrary class?
For example: Could it be anything from an int32 to a UStaticMeshComponent? If this is the case, then I’m pretty sure that it won’t work. (I have also no idea why you would need something like that)

If they have some functionallity in common however, for example they all have one method that you want to call, you could derive all your variableClasses from a parent class. Your variable then stores a pointer to this parent class, and you can assign any object of the subclasses to it. You could then call your method using virtual functions. Also check out TSubclassOf if this direction works for you.

No, seems you don’t get the idea. I want some mechanism to be able to switch variable type depending on other variables value.
So if I switch value in VariableClass variable to ex. MyActorClass, than type of Variable should automatically change to MyActor. So I will not need do typecasts everywhere in my code.

No, I am talking about changing type in Blueprint, it should be possible by tweaking UClass members, but I am not sure if this is safe.

No, this is not possible. C++ is a statically typed language, the whole point is to know the type of variables at compile time, you can’t simply change them at runtime. You will have to use casts.

In your question you said, that Variable and VariableClass are both declared in a C++ class. If that is the case you can’t change their type, for the reasons in my earlier comment. If you want to change their type in Blueprint, you should ask this question again in the Blueprint section, not in the C++ section.

Yes, the type on C++ side is known and static, but on Blueprint side I want it changed.
For example my VariableClass is TSubclassOf
And Variable is of type ABaseActor*

But on Blueprint side I can set VariableClass to MyDerivedActorClass type and want Variable be visible as MyDerivedActor
That would be pretty legal.

Don’t think that question is suitable for Blueprint section, because solution should involve some C++ coding I think.

I am trying to do a similar thing. I have a UEnum as a UProperty in c++ called PropertyA. I want to expose a blueprint property called PropertyB to select a subclass of UEnum(possibly a blueprint type). Then I would like the PropertyA drop down options to be limited to values of type PropertyB. Does this make sense? Any Ideas?