So to be more clear I made a custom print string function in a function library, and I to place this function in a bp of any actor and will print what I want in additional to the actor’s name in the world.
But I kept getting compile error and thus my current work around is add an input pin and when I call the custom print string function I then call the self ref and attach it to the pin.
I’m asking is there a world context based self ref or something as make my workflow easier?
if I use ‘ref self’ in a function within a function library and compile I get a warning stating: ‘Self node Self-Reference cannot be used in a static function.’
I think I understand what you’re trying to achieve, but let me know if I’m wrong. You essentially want a print function where you just input a custom message and it automatically prepends the source Actor’s name to it, and you’d like a workflow where you only have to input the message and not worry about the Actor reference.
If that’s correct, then I can help you. I don’t know if you’re writing your Blueprint library in C++ or Blueprint, so here are two example functions in either:
(Let’s ignore the specific implementation details and focus on the usage.)
Now, since these are static functions, they will always need an input for the SourceActor pointer. There’s no way around this, but we can still achieve the easier workflow you want via Blueprint Macros. Make a Blueprint Macro library, have it inherit from Actor, and then you can use the following two macros:
The key thing to note is that the macros have just one input pin for the message string and internally it automatically populates the SourceActor input with a reference to self. Since macros expand at the site where they are used, this will always be the reference to the actor whose event graph is using the macro.
In your content browser, id recommended in a “blueprints” folder, right click and search “function library” this will allow you to create global functions you can call anywhere
yes you understand my issue. Interesting idea to use a Macro Library and have the self ref there. However, personally this macro library method still falls apart as I mainly use this code in widgets which do no inherit macro libraries sadly. But if use it only blueprints will make sure.
If you’re talking about UserWidgets, you can make this work for them as well. If you’re talking about Slate, then this won’t work. We can make this strategy work for all UObjects as long as you’re just needing GetDisplayName or GetObjectName since both of those are from the UObject interface.
(If you needed specific functionality from Widgets you could always make a specialized version that deals with UUserWidgets / inherits from UserWidget).