“Instantiate” means “to make a copy of”, so you’re creating a copy of an existing card object and then assigning it back to card, so the “card” that you access in the second debug is a brand new card, but with all of the components and public fields of those components copied over. That’s just some general background.
One important distinction: instantiating a prefab and instantiating an existing object in the scene are two different things. A prefab will copy all components and all data, public and private, whereas a GameObject will only try to duplicate it as best it can. Usually that means “just the public stuff”. I have no idea where the value in “dato” is drawn from, but if it’s a public property for a private backing field, that may explain why the value isn’t copied.
I have not delved deeply into this and don’t know how much of the process I grasp properly, but this may have to do with serialization. Try setting the [SerializeField] attribute on the backing field and see if that makes a difference when copying the GameObject. You also have the option of making any data that you want copied public, or creating a data transfer function where you pass the newly created object in as a parameter and copy the old data onto it.
Make sure the class is set to be serializable with [System.Serializable] above the class definition (on the script that contains the “dato” variable). If that doesn’t work, try putting the [SerializeField] attribute over the “dato” definition. If that doesn’t work, post back here.
Is there something weird with DateTime? Because I used to have an int variable, and that worked fine, but when I swapped it with DateTime this happened.
I know I can just copy it from the old card to the new myself, but I just want to know why this is happening,
Yeah, it’s apparently a struct (which I did not know until I checked a minute ago), and structs can’t be serialized (aside from the Unity-specific ones like Vector3 and such). You’ll have to find a different way of getting the value across, or make a serialized class object that can carry all of the information you want from the DateTime and store that instead.
Do you actually need a lot of data from the DateTime object? If you just need a counter or something, you can store the value as a float instead. shrugs