Call a function on an another Component?

I know it’s possible on Unity, but i dont know if it’s possible in UE4 so i need to ask it, sorry.

Can i call a function on an another component?

Like in this scenario, i have put an stupid actor or pawn in my scene.
Put on the actor/pawn an script, which is a class who connects via TCP to an other TCP server.

And now if i press a button via UMG, i call a function on the actor/pawn to send something to the tcp server.

If you can get a reference to the component or actor, you can call whatever functions you want. Getting the reference is usually the tricky part.

Thanks, i got it.
I can now call the function on the other component.
But i have a problem.

I cant send any tcp message to the server.

If i change the function to display a text on my hud, its working.
But if i want to send an tcp message, the editor crashes.
This send function is tested, this is not crashing the editor.

An try catch block seems to not be supported, right?
How can i found out, what the problem is?

Posting your code and the error messages is a good start :slight_smile:

This is my connection script:

.h



private:
	void SendMessage(FString serialized);
public:
	void LoginPlayer(FString _username, FString _password);


.cpp



void UMasterServerConnection::LoginPlayer(FString _username, FString _password)
{
	FString serialized = (TEXT("%s|%s"), *_username, *_password);
	//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("%s"), *serialized));
	SendMessage(serialized);
}

void UMasterServerConnection::SendMessage(FString _serialized)
{
	TCHAR *serializedChar = _serialized.GetCharArray().GetData();
	int32 size = FCString::Strlen(serializedChar);
	int32 sent = 0;

	bool successful = Socket->Send((uint8*)TCHAR_TO_UTF8(serializedChar), size, sent);
	if (successful)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("Gesendet")));
	}
	else{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("Nicht Gesendet")));
	}
}


And this is my UMG Blueprint function

.h



public:	
	UFUNCTION(BlueprintCallable, meta = (DisplayName = "Login Player", CompactNodeTitle = "Login Player", Keywords = "Login Player"), Category = Game)
	static void LoginPlayer(FString _username, FString _password);


.cpp



void UMenu::LoginPlayer(FString _username, FString _password) //This will be called, when the button will be pressed
{	
	for (TObjectIterator<UMasterServerConnection> Itr; Itr; ++Itr)
	{
		if (Itr->GetName() == "MasterServerConnection")
		{
			Itr->LoginPlayer(_username, _password);
			break;
		}
	}
}


Error Message:



MachineId:A1DBA27D4E830F205462B1B5363A84A3
EpicAccountId:ab6a98c395544221bce3c83ab3de7469

Access violation - code c0000005 (first/second chance not available)

""

UE4Editor_AphileGame_198
UE4Editor_AphileGame_198
UE4Editor_AphileGame_198
UE4Editor_AphileGame_198
UE4Editor_CoreUObject!UFunction::Invoke() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\coreuobject\private\uobject\class.cpp:4125]
UE4Editor_CoreUObject!UObject::CallFunction() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:463]
UE4Editor_CoreUObject!UObject::ProcessContextOpcode() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1552]
UE4Editor_CoreUObject!UObject::ProcessInternal() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:673]
UE4Editor_CoreUObject!UObject::CallFunction() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:587]
UE4Editor_CoreUObject!UObject::ProcessInternal() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:673]
UE4Editor_CoreUObject!UFunction::Invoke() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\coreuobject\private\uobject\class.cpp:4125]
UE4Editor_CoreUObject!UObject::ProcessEvent() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1023]
UE4Editor_UMG!TMulticastScriptDelegate<FWeakObjectPtr>::ProcessMulticastDelegate<UObject>() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\public\uobject\scriptdelegates.h:459]
UE4Editor_UMG!UButton::SlateHandleClicked() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\umg\private\components\button.cpp:147]
UE4Editor_UMG!TMemberFunctionCaller<UButton,FReply (__cdecl UButton::*)(void) __ptr64>::operator()<>() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\public\delegates\delegateinstanceinterface_variadics.h:161]
UE4Editor_UMG!TTupleImpl<TIntegerSequence<> >::ApplyAfter_ExplicitReturnType<FReply,TMemberFunctionCaller<UButton,FReply (__cdecl UButton::*)(void) __ptr64> >() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\public\delegates	uple.h:113]
UE4Editor_UMG!TBaseUObjectMethodDelegateInstance<0,UButton,FReply __cdecl(void)>::Execute() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:682]
UE4Editor_Slate!TBaseDelegate<FReply>::Execute() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\public\delegates\delegatesignatureimpl_variadics.inl:440]
UE4Editor_Slate!SButton::OnMouseButtonUp() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\widgets\input\sbutton.cpp:225]
UE4Editor_Slate!<lambda_de96dc3471181973108233c6db1f9843>::operator()() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:4170]
UE4Editor_Slate!FEventRouter::Route<FReply,FEventRouter::FToLeafmostPolicy,FPointerEvent,<lambda_de96dc3471181973108233c6db1f9843> >() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:212]
UE4Editor_Slate!FSlateApplication::ProcessMouseButtonUpEvent() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:4173]
UE4Editor_Slate!FSlateApplication::OnMouseUp() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:4133]
UE4Editor_Core!FWindowsApplication::ProcessDeferredMessage() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\windows\windowsapplication.cpp:1406]
UE4Editor_Core!FWindowsApplication::DeferMessage() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\windows\windowsapplication.cpp:1711]
UE4Editor_Core!FWindowsApplication::ProcessMessage() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\windows\windowsapplication.cpp:706]
UE4Editor_Core!FWindowsApplication::AppWndProc() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\windows\windowsapplication.cpp:628]
user32
user32
UE4Editor_Core!FWindowsPlatformMisc::PumpMessages() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\windows\windowsplatformmisc.cpp:792]
UE4Editor!FEngineLoop::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\launchengineloop.cpp:2319]
UE4Editor!GuardedMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\launch.cpp:142]
UE4Editor!GuardedMainWrapper() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]


//EDIT: Ok, my Socket is NULL. Im in an different instance?