I am making a game that has rounds, and have a script extending Resource
with it's own class_name
, however, in something else, I use export(TowerDefenseRound)var currentRound
, and it isn't working. Can someone help me?
How do I make a custom resource for use with `export`?
It's not a feature yet. You'll have to wait for this PR to be merged. You can however export a regular Resource and use your custom Resource. You just have to go through a lot of other resources to find yours.
@Hakunamawatta said: It's not a feature yet. You'll have to wait for this PR to be merged. You can however export a regular Resource and use your custom Resource. You just have to go through a lot of other resources to find yours.
You can also put in tool mode and add a setter to the variable with the export, so every time a resource is assigned that is not the type you want, send an error
example:
export(TowerDefenseRound) var currentRound setget set_current_round
func set_current_round(value):
assert(value is TowerDefenseRound)
currentRound = value
@TheDiavolo said: example:
export(TowerDefenseRound) var currentRound setget set_current_round func set_current_round(value): assert(value is TowerDefenseRound) currentRound = value
Yes, that's an option, but it would have to export a Resource not a TowerDefenseRound
First of all, I've heard that the assert
keyword only works on dev builds or something. Secondly, I've tried just a big list of resources, but even once I find it and make one, it's an empty resource. I've tried in that slot for a resource and just making a resource in memory, but they both give me a blank resource
object.
- Edited
@Perodactyl said: First of all, I've heard that the
assert
keyword only works on dev builds or something. Yes, it's for testing. It shouldn't really be an issue in the published game @Perodactyl said: Secondly, I've tried just a big list of resources, but even once I find it and make one, it's an empty resource. I've tried in that slot for a resource and just making a resource in memory, but they both give me a blank resource object. I tried this and there are no issues. Are you sure you aren't replacing it with a blank resource in your code? Does your resource have its values properly exported?
I'm pretty sure it did, but I stopped doing that. Now it's a big object filled with all the rounds. It would be good if this question still gets answered for those who find it looking for answers. The code was pretty much just the extends resource
and class_name
though. Even then, it magically became a resource
in the editor instead of the TowerDefenseRound
I requested.
@Perodactyl said: I'm pretty sure it did, but I stopped doing that. Now it's a big object filled with all the rounds. It would be good if this question still gets answered for those who find it looking for answers. The code was pretty much just the
extends resource
andclass_name
though. Even then, it magically became aresource
in the editor instead of theTowerDefenseRound
I requested.
Then the problem is in what uses the resource, not the resource itself
What do you mean?
@Perodactyl said: What do you mean?
You say the class is still changing into a blank resource? If the class extending the resource doesn't have any code, then the problem is with whatever is using the resource. Try creating a new class with a blank export statement for a resource and see if that still replaces it with a blank resource. Does your resource have any exported values? If not, are you sure it's actually a blank resource?