I tried to verify if they are valid or nullptr
, but it doesnt compile it, because I just cant use IsValid
or nullptr
on all types of variables.
This is fixed now, I had to pass the values as parameters from the client function to the server function, both on GrabObject
and on GrabObjectUpdate
, because it turns out that the server cant exactly run the same code as the client (LineTraceSingleByObject
doesnt run on server therefore returning invalid HitResult (and probably a lot of other stuff doesnt run on server, just a reminder)), passing the values as parameters, solves the issue!
Thanks for your help!
Now I have another issue, since anyone could freely pickup Actors/Items/Objects with the tag “A_Item” (thats the class name of the Item), this would mean that an already picked up item can be picked up by multiple players at the same time. So I have added a variable inside the picked up item to check if it is false or true.
The idea is that a picked up item sets a variable inside of it to true, which would indicate that it is InUse
, so other players would check if that is true or not, so they cant pick it up if it is InUse
.
Code inside the picked up item:
//SERVER VALIDATION
bool AA_Item::ServerInUse_Validate(bool Value)
{
return true;
}
//SERVER IMPLEMENTATION
void AA_Item::ServerInUse_Implementation(bool Value)
{
bInUse = Value;
if(bInUse)
{
GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Orange, TEXT("True!"));
}
else if(!bInUse)
{
GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Orange, TEXT("False!"));
}
}
void AA_Item::InUse(bool Value)
{
if(GetLocalRole() == ROLE_Authority)
{
ServerInUse(Value);
}
}
bool AA_Item::GetInUse()
{
return bInUse;
}
Now, on the character, when the player picks it up, it runs the InUse
and ServerInUse
functions, but it doesnt set it for everyone, other players can still pick it up. Do I need to use multicast here? Client picks it up, Server crashes on pickup.
This is how I check it in the character class:
AItem->GetInUse()
- if true it shouldnt be able to pick it up
AItem->InUse(true);
- this sets it to true if the above state is false, and vice versa.
UPDATE: If I run Multicast or Server function on the item, then crashes on Server and works on Client.