#serialization

1 messages · Page 1 of 1 (latest)

woeful bay
#

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

covert valley
#

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...

â–¶ Play video
#
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.

woeful bay
#

oh, so InventoryItem is more of an item slot

#

it's not a plain-old C# object that holds data about the item

covert valley
#

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;

    }
}
woeful bay
#

what is InventoryItem supposed to represent?

covert valley
#

this the inventory slot

covert valley
#

which is just a sprite change

woeful bay
#

but why does it have an Image?

covert valley
#

cos its an image

#

InventorySlot and InventoryItems are just images

woeful bay
#

do you show the item somewhere else on the screen when it's equipped or something?

#

i'm just confused by that

covert valley
#

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

woeful bay
#

okay

covert valley
#

This is the So

woeful bay
#

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

static canopy
#

ow mate, why enum thou?

woeful bay
#

you should probably finish it first

covert valley
#

It just creates the Inventory

#

This is the interactable object which is an Item

woeful bay
#

the tutorial is about how to save and load data

#

so i'd hope it talks about how to save and load items

covert valley
#

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.

static canopy
#

but will it held if you build the game?

covert valley
#

I never built a game so I do not know.

woeful bay
#

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)

static canopy
#

i belive good old brackey have ideal tutorials for beginners

covert valley
#

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

static canopy
#

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

covert valley
#

No you're absolutely right and I agree with that of course.

#

Well thanks for the help. I'll keep looking into it. Appreciate it guys.