# How to get data from a Scriptable Object into a Prefab template

I made a Unity Prefab where about 5 things vary. I then made an invisible GameObject where I use Visual Scripting to hardwire the 5 differing items, in order to create the various GameObjects I need.

It is hardwired, but the Prefab is working really well for my purposes. Here's a sample part of that script, where I'm setting the color of some text and also the sprite.

I'd like to make the whole thing less hardwired, and to keep track of these 5 things in a database of sorts. So I defined a Scriptable Object with the 5 variables in it:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NeemData : ScriptableObject
{
[SerializeField]
private string neemName;

[SerializeField]
private Vector3 neemPosition;

[SerializeField]
private Sprite singleNeemSprite;

[SerializeField]
private string feemText;

[SerializeField]
private Color feemColor;

}


I've been able to easily create Scriptable Objects with data in it, like this one:

I'd like to be able to populate my Prefab with the data from that Scriptable Object, and create GameObjects with that workflow. But I'm not sure the best way to get data out of a Scriptable Object, and combined with a Prefab template to make GameObjects. Any advice?

• Your prefab can have just a variable of your scriptable object private NeemData myDataHolder. For code references, please use the code markup instead of screenshots Jun 6 at 16:05
• @Zibelas I'm using Visual Scripting... what sort of code markup would be best? Jun 6 at 16:10
• Copy paste your code (visual script + screenshot is fine, but NeemData is a script) and just click the script markup in the text field. It should make 4 spaces in front, you might need to add them to the first line and you get a wonderful code format Jun 6 at 16:15
• And keep in mind, scriptable objects are the same for all instances. Your position vector on them will be slightly problematic if you ever want to spawn two cats with that property at different positions Jun 6 at 16:18
• Ah I see now, I should not have set my Scriptable Objects variable to be private... Jun 6 at 18:32

I changed the Scriptable Object variables to be public, and everything worked perfectly.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NeemData : ScriptableObject
{
[SerializeField]
public string neemName;

[SerializeField]
public Vector3 neemPosition;

[SerializeField]
public Sprite singleNeemSprite;

[SerializeField]
public string feemText;

[SerializeField]
public Color feemColor;
}