x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Creating a UProperty

Hi,

I want to have a UProperty as a Member of my Class. However I do not mean having a c++ variable, that is reflected as a UProperty like this:

 UPROPERTY(EditAnywhere, blablabla)
 float member;

but having the member itsself be the UProperty like this

 UProperty member;

or as a pointer of course. I want to use it to store a varibale of dynamic type without templating the whole class. Is this possible? If so, how do I create a UNumericProperty for example? I have tried

 NewObject<UNumericProperty>();

and

 CreateDefaultSubObject<UNumericProperty>("member");

but I dont really understand where UProperty belongs in this context (if it as treadet as a UObject or what else)

Product Version: UE 4.12
Tags:
more ▼

asked Jul 03 '16 at 06:08 PM in C++ Programming

avatar image

pulp_user
1.3k 46 29 59

avatar image Digi Labs Dan Jul 03 '16 at 08:23 PM

I have a hunch this would not work. Instances of UProperty are associated with UClasses, not with instances of UObjects. You may be better off using either a template class or a TUnion. Maybe describe a little more what you are trying to accomplish?

avatar image pulp_user Jul 03 '16 at 08:41 PM

I am writing a framework to bind an input to several actions that go like this: press key-> add x1 to y1, set x2 to y2. press other key-> set x3 to y3 and so on

With x being a u property, I can use this on members of any class and any type which is quite convenient. I do this by having the inputAction call a method that calls a multi-cast delegate. In this delegate I store pointers to x and y as payloads, and the actions as a function call.

What I wanted to use this specific construct for is to have an easy way of serializing it:

I currently save the name of x (since it’s a uproperty) and the tag of its component (which I will keep unique). I can then just find all my pointers again by searching for the tag and the property name. I still have to save y though. This question basically would just have avoided having a single serialization-class for each type.

This is however not a big issue, I just wanted to know if it was possible. I think I will simply template the class (unless you have a better suggestion). Thank you for your answer.

avatar image pulp_user Jul 03 '16 at 08:44 PM

I just realized I can call the delegate directly from the action, since executing it is done using the broadcast function :D

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

It is, I think, technically possible to reference UProperty of an existing class in another class, but I assume a reference to a UProperty is not reliable as it will change if the class is modified either from compiling c++ code or compiling blueprint.

The safer way to do it is to save the UClass where the property is in along with the property's Name. Both are guaranteed to be serialized properly and getting the UProperty instance is trivial if you have those two.


Creating UProperty on the fly just like what you plan to do, however, is not possible. UProperty is a special object that is stored as a linked list in a class, it is part of the reflection system that works like a map to get a certain value from a a certain offset in an object's byte data. UProperty that is created outside of the reflection system will not work properly and will be a dangerous map to a value in an object, and I just don't see it as implementable without changing the engine code.

more ▼

answered Jul 03 '16 at 09:44 PM

avatar image

Heapcleaner
541 15 5 19

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question