#serialization
1 messages · Page 1 of 1 (latest)
No, because you can just serialize their fields and then recreate them later
public class InventoryItem {
public string customName;
public int count;
public ItemSO itemDefinition;
}
I'm guessing you have something like this
I am using a custom class instead of script I got from github let me show you how I keep player data so you can have an idea
https://www.youtube.com/watch?v=z1sMhGIgfoo I followed this tutorial if you've ever encountered btw.
Data Binding in Unity can speed up your save times tremendously by keeping the persistent state of the game ready to save at a moments notice. Data binding is a fast and efficient way to save data quickly at runtime, and can help improve your data modelling. Let's build a Save/Load system to see this in practice.
NOTES: If using the Serializa...
using UnityEngine;
using UnityEngine.UI;
public class InventoryItem : MonoBehaviour
{
[HideInInspector]
public Item item;
public Image image;
// Start is called before the first frame update
public void InitializeItem(Item newItem)
{
item = newItem;
image.sprite = newItem.image;
}
}
this is my inventoryItem.
and the Item is the scriptable object.
oh, so InventoryItem is more of an item slot
it's not a plain-old C# object that holds data about the item
but I also have an InventorySlot
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InventorySlot : MonoBehaviour
{
public Image image;
public Color selectedColor, notSelectedColor;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void Awake()
{
Deselect();
}
public void Select()
{
image.color = selectedColor;
}
public void Deselect()
{
image.color = notSelectedColor;
}
}
what is InventoryItem supposed to represent?
this the inventory slot
the InventoryItem. When I initialize it gets the item data from Item SO
which is just a sprite change
but why does it have an Image?
do you show the item somewhere else on the screen when it's equipped or something?
i'm just confused by that
Ah yes In my hand and in the hotbar
the hotbar is just the what I call Inventory which has 4 slots
This is the InventorySlot
okay
This is the So
in that case, you're just going to serialize which Item you had equipped in each of your InventoryItem components
I presume the tutorial talks about this, though
ow mate, why enum thou?
you should probably finish it first
I have been doing it for several days now
It just creates the Inventory
This is the interactable object which is an Item
Hm okay
the tutorial is about how to save and load data
so i'd hope it talks about how to save and load items
Ahh yes It does for sure.
I followed it and can hold player data
but then he does some weird stuff when its inventory.
I did not get a single thing.
but will it held if you build the game?
I never built a game so I do not know.
if you can't understand the tutorial at all, then you need to start with something more basic
(or you need to go through the tutorial again more slowly)
i belive good old brackey have ideal tutorials for beginners
Yeah you're right. I just did not get the part about the inventory thing as his is different than mine.
I thought I could tweak things a bit but yeah
it may be uppseting advice but generally i would recomand to start from deeper understading of programing and your programing language and than get back to working on game :/
there is a lot of stuff to understand about architecture and design patterns... definitely look into design patterns