Is it possible to use editor value in class constuctor
Hello. Im not sure the title of the question is even 80% accurate.
Anyway I want to spawn an array of "child actor components" (no problem there ( for now ) ) depending on the size of a UProperty i have set up. But when i tried that ofc, it defaults to 0 ( as that is default ) at first. But even, if I change it in the editor it stays 0, throughout the construction and on my begin play" breakpoints - it has been changed to the value given from the editor.
So is it possible through 'some means' to be able dynamically change a exposed to editor property and for it to effect constructor or should i just do the components creation in the "begin play"
asked Nov 18 '15 at 03:43 PM in C++ Programming
Yes, it's possible using the OnConstruction function. Basically, this is called each time you modify a property in the editor. So, if you want to have 2 actor component after you input 2 in the editor, Spawn those components in the OnConstruction call.
You can do it in Blueprint or C++.
The C++ function signature you need to overide is this :
I recommend using the #if WITH_EDITOR macro here just so its explicit this is only true in the editor.
After that, you can spawn components. Here is an example:
In this scenario, nNbComponentsToSpawn is the variable you have change value of, and it's going to spawn the right number of components (sphereComponents in this case).
I think this is what you wanted?
Hope this helps,
answered Nov 18 '15 at 09:01 PM
Well, a constructor (as i'm sure you know :D) simply represents the 'layout' or floor plan of the class and when it becomes an object the variables are the defaults when constructed.
So if I understand your question correctly then I would say no it is not possible. After the initial construction of course it is possible to edit the values but otherwise if you want the default values to be something else then place it in the constructor.
If you want to change it at run time rather then creation then you've got the right idea. Use BeginPlay.
answered Nov 18 '15 at 05:15 PM
Mark James G
Follow this question
Once you sign in you will be able to subscribe for any updates here