Using UPROPERTY over const variables

Hello Everybody,

I am trying to implement my code below in my class’s header file, but the build fails and I get a message saying “Const properties are not supported.” in the Output.

	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = MyCategory)
	const float MIN_SIZE = 1.0f;

Question: How can I make a constant value that is also exposed in my Blueprint?

Any help is greatly appreciated,

Farshooter

I could see a few ways of getting around this:

  1. You wrap this variable in a method and expose that to blueprints (rather than the raw variable), UFUNCTION(BlueprintCallable) float GetMinSize() const { return MIN_SIZE; }
  2. You just remove the const in C++, comment that it’s “effectively” const but the modifier is removed due to needing it exposed to BPs.

Honestly, I’d probably just go with #1 since this is supposed to be read only (and hopefully you don’t really need to display it or anything).

1 Like

Thank you for the information. I think the first solution is great.

You did not understand the essence of the question. A parameter with a constant value is needed, which can be set in the editor mode on the scene, This variable should be prohibited from changing the value both in bluprint and in C++.

1 Like