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