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…

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.

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.

No problem :slight_smile: