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"

Why are BlueprintPure and const incompatible?

UFUNCTION has the BlueprintPure parameter for tagging functions without side-effects, and C++ has the const keyword for, roughly, the same purpose. But if you try to declare a member function such as:

 UFUNCTION(BlueprintPure, Category=Foos)
 FVector GetFoo() const;

UHT will complain with the message:

 Cannot mark function 'GetFoo' as both 'BlueprintPure' and 'const'

Why is that? Const-correct code is generally A Good Thing in C++, but presumably BlueprintPure allows Unreal to reap some sort of optimization. Am I losing anything if I just tag my const function as BlueprintCallable instead?

Product Version: Not Selected
more ▼

asked Jul 02 '14 at 11:32 PM in C++ Programming

avatar image

41 2 4 9

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

1 answer: sort voted first

UFunctions marked as const are always treated as BlueprintPure, so marking a function as const and BlueprintPure is redundant, and that's why UHT complains. There are a couple things that are debatable about this:

  1. Conflating BlueprintPure and C++'s const keyword is a little dubious because C++ const does not imply purity. const functions may modify mutable members and global state.

  2. This error could just be a warning, because it is not fatal, it is simply redundant.

Current best practice is to mark const functions as BlueprintCallable and be aware that they will be treated as BlueprintPure by the compiler.

more ▼

answered Jul 03 '14 at 06:55 PM

avatar image

Dan.OConnor STAFF
495 14 7 17

avatar image Skrapion Jul 03 '14 at 08:51 PM

Yeah, that does seem dubious. Thanks for the clarification!

avatar image DevVictor Oct 24 '15 at 01:17 AM

Another vote for 'dubious / do not want' (and removed from local source)

My use case where this is not acceptable is trying to use ExpandEnumAsExecs on the output param of the const function - the BlueprintPure hides all exec pins, including the enum execs.

The function is also used from c++, where the const is required. (I could add a duplicate function, but, no.)

modified UHT:HeaderParser.cpp

 -  FuncInfo.FunctionFlags |= FUNC_BlueprintPure;
 + // @ : override if any ExpandEnumAsExecs are specifically set
 + if (!MetaData.Contains("ExpandEnumAsExecs"))
 + {
 +      FuncInfo.FunctionFlags |= FUNC_BlueprintPure;
 + }

(note that just removing the feature entirely will completely break a lot of built in nodes that are assumed pure due to this)

(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