Yan
Yan

Reputation: 1

Godot - import animation files from web in runtime

i am trying to pass some assets thorough the web to my game.

in this process we have few textures and 1 animation file.

when trying to load the file i get:

open: user://animTest.tres:1 - Parse Error

the end goal is to be able to add this animation to AnimationPlayer through add_animation func..

any ideas how it is possible to import an animation file from the web?

tried to get a file via http request, and load it to a new animation object. didnt work - get a parse error.

Upvotes: 0

Views: 176

Answers (1)

Bugfish
Bugfish

Reputation: 1729

After setting up a Godot 3.5.1 environment I tried to reconstruct your problem with the informations you gave us.

What I did in Godot:

  • Creating a scene containing a Animation Player and a simple Sprite
  • Created an animation for the sprite and saved it to a file named test.tres
  • Removed the animation from the animation player.

Then for the sake of imitating the loading from a server, I made a simple local file server and put the test.tres file there, so Godot will be able to download it.

Next I created a script in my scene to load the file. Therefore I created a HttpRequester Node and downloaded the file:

func _ready():
    $HTTPRequest.connect("request_completed", self, "_on_request_completed")
    $HTTPRequest.request("http://127.0.0.1:8080/test.tres")

Then in the signal I saved the file on the system and then loaded it as an animation. Playing the animation did work without problems:

func _on_request_completed(result, response_code, headers, body):
    var txt = body.get_string_from_utf8()
    var file : File = File.new()
    file.open("user://anim.tres", file.WRITE)
    file.store_string(txt)
    file.close()
    
    
    var anim = load("user://anim.tres")
    $AnimationPlayer.add_animation("test", anim)
    $AnimationPlayer.play("test")

Of course this example misses error handling and multiple files, but it shows a way to load an animation from a fileserver and playing it

Upvotes: 1

Related Questions