#How to serialize a ScriptableObject?

1 messages · Page 1 of 1 (latest)

fast fractal
#

I want to pass the CardSO through Rpc calls. But it says I must serialize and deserialize it.

#

Ping me when you answer. Sometimes I forget I opened a thread

solar turtle
mortal thunder
#

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

solar turtle
# fast fractal How?

just a public int ID; above the card sprite. A list of cards in a separate SO is also an option.

fast fractal
#

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

solar turtle
#

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

fast fractal
#

Can you show me an example for a function?

solar turtle
fast fractal
#

I can't understand the ReturnBool.Value. I know it gives you the value. but how does it work here?

solar turtle
fast fractal
#

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