#How to serialize a ScriptableObject?
1 messages · Page 1 of 1 (latest)
Give the Card SO an int ID and then send the ID in the RPC
How?
The way i've done it in the past is to have a ScriptableObject that hold a list of my scriptableobjects, like
public class ScriptableCardManifest : ScriptableObject
{
[field: SerializeField] public List<ScriptableCard> Cards {get; private set; } = new List<ScriptableCard>();
}
and then you could get the index of a given card from this list, pass via rpc and then get the object reference via indexing into the list on the other side
just a public int ID; above the card sprite. A list of cards in a separate SO is also an option.
Alright. I guess I understand what to do now. Thank you guys
Another question.. how can I request something from the server, pause the function and wait until I receive a respond? Like async and tasks
That is tricky. RPCs can not have a return type. So there is nothing to wait for. The server can make a reply RPC or update a network variable then you can have the client listen for that. After you call the RPC, you could use Awaitable.WaitUntilAsync() or a coroutine with yield WaitUntil() to wait for that update from the server
Can you show me an example for a function?
something like
IEnumerator WaitforRPC()
{
ToggleBoolRPC();
yield return new WaitUntil(() => ReturnBool.Value);
print("Bool has been flipped");
ToggleBoolRPC();
}
So,
ReturnBool is a NetworkVariable. the Lambda expression means when the value change go to the next line?
I can't understand the ReturnBool.Value. I know it gives you the value. but how does it work here?
The coroutine will wait until the value of ReturnBool is true. You could also subscribe to the ReturnBool.OnValueChange event if you want to respond anytime the value changes
This look somewhat complicated to implement
I'm thinking of redesigning the whole logic of the game. Instead of asking for the card value from the server. Let the server do all the work while the client sends what he wants to do
And making the card value only when you want to look at it
This way the SendCardValueRpc can just flip the card to show it's value only. While the rest of the work is the server doing