#Preloaded Custom Resource has wrong type (v4.3.rc3.official)

1 messages · Page 1 of 1 (latest)

astral spindle
#

I have a custom resource class CombatEffect, and two .tres resource files with CombatEffect as their Script. These two resources are identical, except one is preloaded in a separate resource file. However, this code:

func _ready() -> void:
    var effect1 := preload ("res://Data/CombatEffects/EffectThatIsPreloadedElsewhere.tres")
    var effect2 := preload ("res://Data/CombatEffects/EffectThatIsntReferencedElsewhere.tres")
    print("Effect1")
    print(effect1 is Resource)
    print(effect1 is CombatEffect)
    print("Effect2")
    print(effect2 is Resource)
    print(effect2 is CombatEffect)

Prints the following:

Effect1
true
false
Effect2
true
true

If I switch the external preload to a load, everything works as expected, but this fails specifically when preloading it elsewhere. I was not able to reproduce this issue in a sample project, so it doesn't seem like it's just a straightforward cyclical reference issue or anything like that. Does anyone have any ideas as to what might be causing this? Thank you.

modest star
#

@astral spindle Hmmm, don't know. Does this _ready() function belong to a node?

astral spindle
modest star
#

@astral spindle Well, this doesn't answer your question, but why don't you use @export instead of the preloads? They are cleaner and don't depend on string paths. Who knows, maybe they solve your problem as well.

astral spindle
#

The Node that has this issue doesn't have a scene file, it's just the script file, and it's only instantiated via code, so I don't think there's a way to specify an @export in this case. But that's a good idea in general so I'll try to keep that in mind for other stuff, thank you!

modest star
#

You can still attach this script file to a scene and instantiate that scene instead of the script to see if this method solves your issue. Would be an interesting experiment.

violet knoll
#

did you try adding an explicit typehint? if it's not a combateffect, will it error?

slim drift
#

Shouldn't preload just be load in this situation? Why not preload into a constant, so that the load happens along with the scripts?

#

If the class name isn't available yet, then the timing is off somehow, it's not actually initialized yet

#

Maybe preload defaults to load in this situation if the object isn't already loaded, but since it's already being preloaded and will be available next frame, it just does nothing?

astral spindle
astral spindle
slim drift
#

I'm not really clear on what preload does when it's not constant/static, the docs are vague and there's a lot of conflicting information out there

astral spindle
#

Interesting! Unfortunately it seems that switching the preload to a const did not resolve it in this case. But I'm going to read this guide, thank you!

hearty notch
#

hey, do you preload the CombatEffect file somewhere in your project directly? I recently had a very similar issue and that was the cause

#

also somewhere on the github repo I found an open issue regarding this

#

sadly I can‘t find the link anymore but you might be able find it by searching for it

astral spindle
astral spindle