Scriptable Objects>


#1

So I came across this tutorial about Scriptable Objects. Basically making an object in which I could store information on and use later.

So in the video: https://www.youtube.com/watch?v=aPXvoWVabPY

Brackey’s does this dope thing where he’ll make like the Health, Name, Image etc, and then reuse that information on other objects, and it makes it simple and easier to keep track of data.

I’m positive there’s a way to do this in playcanvas, but not sure how. It’d be like making my own asset that I then can attach other assets too. Similar to like a material that takes on textures, and then that material is applied onto a model, but instead I make my own asset that takes on let’s say ‘Health’, ‘Name’, etc and then be able to extract that data for later use.

Let me know of a way to do such a thing since I’m a noob.


#2

Hmm… There’s a not a one to one type in PlayCanvas. The closest you can get to it is using JSON assets but things like images/textures etc are not assignable. You would to do things like look ups etc in the asset registry by name/id etc.

I do something similar here: https://playcanvas.com/editor/code/560025?tabs=12879307,12879345


#3

So you can’t really make an interface that you can plug and go then? You’d have to use the JSON stuff?

I’m not sure how that works btw, can you give me any documentation on this? Something where I can plug in the JSON as an attribute to a Script then pull from that JSON to find the right assets.


#4

I may have something working! The example you sent was overwhelming haha Didn’t understand what was needed and what was over the top epic coding.

But a bit of baby stepping got a reasonable result. I’ll come back later with findings.

It would be great though to create attributes within the JSON file so you can drag and drop or input values outside of it, but it’s no big hurdle :wink:


#5

I found this useful to check my json too


#6

So I have found the best solution for what I need for now. I would REALLLLLY love to just plug and go into my json or some other asset type, but I don’t know how to make custom asset types so I’ll just use the JSON method since it is CLEARLY way more manageable

Here is the JSON file that I’ve made as a test.
image

And here is the script that I use to change the features of the JSON which can be handy when it comes to gameplay, obviously these are simple tests, but I believe all the pieces I need are here to make a more complex game without getting f’n lost in all this code.

Next test this with something soon.


#7

While it is possible to make custom asset types, unless you extend the Editor (with a Chrome extension for example), you won’t be able to create or assign it in the asset registry except through code.

Not in the same way as Scriptable objects, no.

Unfortunately, that was the only project I had that used JSON data. The idea was to show some example JSON and how to create a script attribute for it. The tough part is what to do when you want to assign something like a texture asset to it. It’s not possible but you can use the name (as long as it is unique) to do a search in the registry for the asset (this is what I did in my project). Not the most efficient though. There are a few ways to get around it though if it becomes a bottle neck.

One part I’m not too keen on is changing the JSON data (in your case, making equipped to true). IMO, the JSON data should be ‘read only’.


#8

Why wouldn’t I want to change the JSON?
I think ultimately I may not change the JSON data, but curious too the reasons you wouldn’t.

Do you have any examples of this perhaps? I have seen the extend stuff in code, but not sure what that is either. Trying to really master playcanvas since it has so many of my fav features.

But in the example of scriptable objects, it just would be nice to change information via the editor versus the code editor, but it is a minor inconvenience, nothing earth shattering.


#9

If it’s a shared data asset that other scripts use, arguably, changing the data may cause unforeseen knock on effects in other scripts. YMMV, I would keep it as read only so I don’t have to worry about dependency issues.

Examples of which bit? Creating a new asset type or extending the editor?


#10

Yea both :smiley: or anything you think could help me get started.