The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

The title says it all, I am writing a script that changes the size of enemies but when I touch the enemy every enemy grows not just the one I am touching.

func _on_Hit_body_entered(body):
    body.radius += 50

very simple but doesn't work on just the one I touch. Is there a way to have prefabs like unity that have their own instance of the script so this doesn't happen?

in Engine by (14 points)

I tried this code and it created a new instance but when I collide it still makes all of the others grow too

That’s what I do, I can track them all that way.
Have a Google, there should be a ton of tutorials for this.

cool cool, I have searched a bunch but maybe I am searching the wrong things.. Thanks for the time man, I will see what I can figure out and try a new project and if I can't get it maybe I will just go back to unity

Yes, it's all about what you feel comfortable with. I started with Unity, went to GameMaker, then Defold, back to Unity and then Godot.
I like Godot, I prefer it to all the others I've used. It doesn't mean it's the best, I just feel comfortable with it.

sprite duplication in godot is really weird

1 Answer

0 votes

Here is an example of a universal prefab loader with caching and fault tolerance. It is part of my modified asynchronous resource loader. The above method will return the original instance at the first moment of loading, cache the instance, and then return independent duplicates when you re-access it (which is what you need to solve your problem). The method will work with any type of resource

var _cache: Dictionary = {}
var _duples: Array = []

func load_unique_resource(path: String):
    if _cache.has(path) and is_instance_valid(_cache[path].instance):
        if path in _duples:
            return _cache[path].instance.duplicate()

        _duples.append(path)
        return _cache[path].instance

        var f: File = File.new()

        if f.file_exists(path) or ResourceLoader.exists(path):
            var r = ResourceLoader.load(path)

            if not r.has_method("instance"):
                if r.has_method("duplicate"):
                    return r.duplicate()

                return r

            _cache[path] = { path = path, loader = r, instance = r.instance() }
            _duples.append(path)
            return _cache[path].instance

        return null
by (22 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.