EditAnyWhere not Working Within Editor ?

Hello mates.

Was just doing a simple workout with C++. I have a very simple class that is basically a trigger box when something gets in turns on a light.
Everything works fine and compiles without errors. Just the the float variables I define in .h doesn’t seem to be re-adjustable in editor. I have also came across this:

Here are the codes:

.h




public:

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Lights")
	float InitialIntensity;


	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Lights")
	float InitialAttRadius;




.cpp (In constructor)




	InitialIntensity = 3000.0f;
	InitialAttRadius = 1000.f;

	MeinLight->Intensity = InitialIntensity;
	MeinLight->AttenuationRadius = InitialAttRadius;



In here no matter what I do they stuck in their pre-defined values in the .cpp

Thanks for the help.

1 Like

If I remember things right, the constructor for actors in c++ just sets up the template version of the actor.
For something like the Blueprint Construction script in c++ you need override the OnConstruction(const FTransform& Transform) function.

Also when I tried it with packaged builds the OnConstruction function was not called, so you need to make sure to set up your actor on BeginPlay, unless this was fixed.

Hmm not sure if I followed you correctly but let me try it and return tomorrow. Thanks.

On the other hand I get the feeling it should be much easier somehow.

1 Like

It looks like you’re only propagating your settings to the actual light component once, at the constructor, which is only run when the object is first created (and with the default values). If you move the two assignment lines ([FONT=Courier New]MeinLight->Intensity = … and [FONT=Courier New]MeinLight->AttenuationRadius = …) to the OnConstruction function (by overriding it as per Tomura’s suggestion), they’ll be run every time you modify the actor in the editor.

You’ll also want to override BeginPlay (added by default if you create a class from the editor) to execute these lines when the game starts, though I’m not sure it’s required if they’re directly modifying UPROPERTY values from the editor which should be saved with the level (but I’m not 100% sure).

@ kukiric and Tomura

12096243_802449669863503_8218251356955833473_n.jpg

Thanks getting and overriding an OnConstruction solved it. There was no need to override BeginPlay. At least currently it works just fine.

You da mates ! :wink: