How to get the return value from RPC functions?

hello
I’m currently making a multiplayer game.

I already know that the RPC functions can’t have return values.
however, i want to get an actor’s reference that is created on the server machine.

Is there any way to send the actor reference to the client after the actor has been created on the server?

first of all, I created an Actor from server side. and i tried to send the actor reference to client.
it works on server machine but it doesn’t work on the client machine.
what should i do?

header

UFUNCTION(Server, Reliable)
void SpawnBuildingOnServer(UClass* SpawnedBuilding, const FTransform& SpawningTransform);

UFUNCTION(Client, Reliable)
void PlaceBuildingOnClient(ABaseBuilding* SpawnedBuilding);

cpp

void AClass::SpawnBuildingOnServer_Implementation(UClass* SpawnedBuilding,
                                                                const FTransform& SpawningTransform)
{
	if(HasAuthority())
	{
		FActorSpawnParameters Params;
		if(ABaseBuilding* SpawnedActor = GetWorld()->SpawnActor<ABaseBuilding>(SpawnedBuilding, SpawningTransform.GetLocation(), SpawningTransform.GetRotation().Rotator()))
		{
			if(SpawnedActor)
			{
				PlaceBuildingOnClient(SpawnedActor);
			}
		}
	}
}
void AClass::PlaceBuildingOnClient_Implementation(ABaseBuilding* SpawnedBuilding)
{
	if(!BuildingComponent)
	{
		UE_LOG(LogTemp,	Warning, TEXT("Not BuildingComponent"));
		return;
	}

	if(SpawnedBuilding != nullptr)
	{
		UE_LOG(LogTemp,	Warning, TEXT("Building Name: %s"), *SpawnedBuilding->GetName());

         // Server prints this log
	}
	else if(SpawnedBuilding == nullptr)
	{
		UE_LOG(LogTemp,	Warning, TEXT("Can't Create!!!"));
         // Client prints this log
	}
}

help me please :disappointed_relieved:
thank you in advance!!

I’m assuming the building is replicated?

can you try adding this to your DefaultEngine.ini

[ConsoleVariables]
net.AllowAsyncLoading=1
net.DelayUnmappedRPCs=1

1 Like

I really appriciate it!
it works as i intended :slight_smile: