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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Component Function Accessibility Issue

Hello,

I have been having a hard time wrapping my head around how to "guard" the accessibility of functions I create within a custom actor component (and I assume the solution here will apply many other places). Let's say I have an actor component I'm building, "ClockComponent":

 UCLASS(meta=(BlueprintSpawnableComponent))
 class LEARNINGS_API UClockComponent : public UActorComponent
 {
         GENERATED_BODY()
 
 public:    
         UClockComponent ();
 
         UFUNCTION(BlueprintCallable, meta = (DisplayName = "Start Clock"))
         static void StartClock();
 };

Note that the actual "thing" I'm doing is more fleshed out and complex than this simple example. What my issue is, is that the StartClock function is available to call within a blueprint, whether or not the component is added to an actor. Is there any way to hide functions, unless they are pulled off of the component pin?

I have also tried this:

 UCLASS(meta=(BlueprintSpawnableComponent))
 class LEARNINGS_API UClockComponent : public UActorComponent
 {
     GENERATED_BODY()
     
 public:    
     UClockComponent ();
 
     UFUNCTION(BlueprintCallable, meta = (DisplayName =  "Start Clock"))
     static void StartClock(UClockComponent* clock);
 };

That produces the same node, with an input for a UClockComponent reference, but it can be executed without having to plug in a reference or pull off of the ClockComponent. I've even thrown in an "IsValid(clock)" branch in my code, but it keeps chugging along even if I don't plug anything into the reference pin on the blueprint node graph. I can't help but worry about what's actually being referenced, when it seems that my function is being treated as BlueprintPure.

Any help with that would be awesome. I have searched and searched, been over the same wiki entries and forum posts and chapters in outdated books dozens of times over the last 13(!) hours now. One thing I came across, was abusing IsValidLowLevel is bad, apparently. Also, I don't really want to check for validity. I only want to be able to call functions from a component, from off of the component node. I don't want them showing up in the node library when a user right-clicks, or at the least I want an error if the component isn't plugged into the function (pure included).

As a bonus: does setting a function as BlueprintSetter/BlueprintGetter have any benefits? There is literally no documentation on it. Is it just for human-readability? Seems weird to have those, if there is no advantage over BlueprintPure or BlueprintCallable...

Product Version: UE 4.18
Tags:
more ▼

asked Dec 20 '17 at 06:00 AM in C++ Programming

avatar image

Derjyn
70 1 8 8

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

1 answer: sort voted first

Hey there, why are you making the function static? If you have an instance of the component and you want to start it you don't need the static modifier, just call the function. When you set a function as static it doesn't really belong to the class, it just sits there.

more ▼

answered Dec 20 '17 at 10:49 AM

avatar image

xlar8or
6k 161 129 304

avatar image Derjyn Dec 20 '17 at 05:00 PM

Wow. That really bit me in the face. Banging my head on the wall over something so simple. Usually the case, ha.

Thanks for that seconds set of eyes and calling that out.

avatar image xlar8or Dec 20 '17 at 08:06 PM

No problem :)

(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