Is it possible to print a string from blueprint function?

I’m attempting to debug a blueprint function and it seems that [watches do not work inside of functions][1]. Instead I am attempting to print log messages out with the information that I need. Doing so produces an error log stating “Could not find a pin for the parameter __WorldContext of IsWithinRange on Is Within Range” (See attached screenshot).

Is it possible to use the Print String node inside of a function blueprint? If so, how?

You can definitely print strings inside functions, but I don’t know what is wrong with the function you have shown. I don’t think it has anything to do with the print.

It seems to me that this kind of error usually arises in copypasted blueprints. Anyway, the problem is almost definitely in the output node. Is your function entirely blueprint-based?

Since we cannot see the eventgraph to see whats firing into IsWithinRange I can only guess and from that it might be that there is something not giving a valid input to the IsWithinRange function or there is not valid value being generated with the function GetDistance.

I would disconnect the IsWithinRange and see if the error goes away if it does just reconnect one or two nodes inside until the error comes back if you cannot find the problem by tracing over the eventgraph. Please post that and the breakdown of the GetDistance.

Looking on source code snippit in API refrence,

…it really does not matter what you pass in WorldContextObject you could as well place null there because it being overrided on first line of function. I don’t really see point of that argument as it’s useless and thats why it might be hidden. By default the argument is set to “Self”

Considering he using GEngine to get that world context object, it better to use it when actor is fully initiated (after BeginPlay?)

in 4.5 code does not really change:

https://github.com/EpicGames/UnrealEngine/blob/69b5693c869697b828e1f2c24004ff1481b5fb98/Engine/Source/Runtime/Engine/Private/KismetSystemLibrary.cpp#L145

As well the pin is still maked as hidden, so i don’t know why you seeing it

https://github.com/EpicGames/UnrealEngine/blob/69b5693c869697b828e1f2c24004ff1481b5fb98/Engine/Source/Runtime/Engine/Classes/Kismet/KismetSystemLibrary.h#L179

I have found the problem for this, the WorldContextObject is an input for PrintString that is usually hidden but if you try to use PrintString in Macro that doesnt extend Actor or in a FunctionLibrary then you cannot pass the reference of the calling Actor (if there is one).

In my version (4.5 preview) the pin shows up as World Context Object and I cant pass an Object or an Actor reference through it, it means I cannot use PrintString in the above mentioned conditions.

It wont let me pass anything to world context object, the issue is in the blueprint compiler not the C++, passing null to it causes the PrintString not to print. Im not sure why that is but I have practical knowledge not just reading from documentation oh how things “should” work.

Im not sure why the pin doesnt show up at all when its in an Macro Library extending from Actor, not Object. It could be that Macro and Function Libraries dont have instantiated game objects, hence no context.

Perhaps if they just called () on self object that might work better.

Yeah but its not self, as you said it gets reassigned in the first line of the function.

I personally want to be printing to the message log anyways not the game log.

UWorld* UEngine::GetWorldFromContextObject(const UObject* Object, const bool bChecked) const
{
if (!bChecked && Object == NULL)
{
return NULL;
}

check(Object);

bool bSupported = true;
UWorld* World = (bChecked ? Object->GetWorldChecked(bSupported) : Object->());
return (bSupported ? World : GWorld);

}

This can return null!

What it should do and what it does do are two entirely different things!

If it wernt for the pin showing up I wouldnt havent even known there was an issue with it returning null. It does work in a Macro library, I can pass self or extend from Actor but I cant pass anything to WorldContextObject in a function library, if the pin is usually hidden though, say the function Context is infact Null also but the pin is still hidden thats the problem.

The blueprint compiler is giving the wrong error there, its close but it should be _WorldContext on the PrintString.

But you got

DefaultToSelf=“WorldContextObject”

Which i assume means by default it pass Self, which is object the function is executed in

Im not sure why that is but I have practical knowledge not just reading from documentation oh how things “should” work.

Because it should work as code points out, WorldContextObject is hidden and by default is self and as i said it does not matter if you pass and it’s not null because it self. Only point i can see this fall out is GEnigne being null where may happen is actor and game is not fully initiated at point of call.

But this can happen when Wolrd does not exist or Object is not fully initiated

So i think it’s called where it is called from which he didn’t said, also Macro should work which should paste code inline, or else it’s not Macro and should be consider bug. I can see not working in function libery

Yes I’m running into this same problem where I have one BlueprintLibrary function calling another (which calls ‘Print String’). Luckily it was only used for debug purposes so I just unhooked it - but it would be nice to get this fixed.

I’m also running into this problem with a function calling a function. Kind of depressing when you can’t even print a single string in blueprint. Stuff like this makes wonder whether blueprint is viable or just a demo tool and C++ is really the only way to go.