Download

Programming problem, Server logic

I’ve made a “Server Spawn Item” void in my character class and it all works fine with NO errors, but when i want to store the spawned item
as a reference in a variable it doesn’t work. I think it isn’t working because it cant find the empty variable in the header file due to the fact that
the code is being executed on the server and cant find the variable on the server (the variable is stored on the client).

But i cant find a way around it… i need to store the spawned item as a reference so i can call code locally to be executed on the server.
Other wise it wont be able to find the spawned item (“ReferenceVariable” is undefined error).

Locally call code example -


ReferenceVariable->ServerStartDrinkItem();

My original code- (NOTE - the code compiles successfully despite the red lines)

Thanks -

Have you set ReferenceVariable up to be replicated? For example:

In Base_Character.h:


**UPROPERTY(replicated)**
ADev_Weapon* ReferenceVariable;

In Base_Character.cpp:


void ABase_Character::GetLifetimeReplicatedProps( TArray< FLifetimeProperty > & OutLifetimeProps ) const
{
	Super::GetLifetimeReplicatedProps( OutLifetimeProps );

	**DOREPLIFETIME( ABase_Character, ReferenceVariable );**
}

edit: Also make sure that your weapon class is set to replicate, by setting bReplicates = true in its constructor.

Thank you that worked flawlessly. :smiley: