How to import/remove an object into/from the scene while the game is running?

How can one import an object (an obj) in an Armory game while the game is running? For example, I want to import an object (car.obj) when I press a key and remove that object if I press another key. I wonder how this would be possible using a Haxe script or a logic node set up?

In case it is not possible to import an obj file directly into the scene I don’t mind converting the objects to another format that Armory supports. I just need to be able to import my objects into the game environment and remove them. Is that possible?

The closest things I found are this and this Armory example scripts but they do not import objects that are stored on disk. For my work, I need to be able to dynamically manipulate objects, store them on disk and load them into the game and these scripts seem to not be helpful for me.

There’s this example here which seems to load and stream an obj file from an external source - although it’s from a server in this example, I’m sure it can be easily reconfigured to load local hard drive assets.

Hope it helps :slight_smile:

1 Like

@Naxela Do you know how to remove objects from the scene?

I think you can just use the remove object node if you’re doing it through logic, or alternatively just use the object.remove() if you’re doing it through haxe. I’m not fully sure if it works though, I haven’t tried it myself

With nodes you can use the spawn object and remove object to add and remove object to your scene.

With the Spawn Object you can only add an object which is already in the scene but is not visible to the camera, as far as I know. Am I right?

With Remove Object nodes you can only remove objects that are already in the scene which might be useful for me.

Yes the spawn object needs to be in the scene but it doesn’t have to be in any visible layer. So you can stick every thing you want to spawn on a separate layer that does not load originally.

What about memory issue then? I have about 200 meshes with moderate number of vertices. Loading them into the scene and making them invisible on a web application doesn’t make sense I think.

Have you tested it? it may take up memory but if the game still runs well then it would work. Have you tried looking into what was said above and change the script to pull from a drive rather than a server. A server is a drive so it should be just changing the path. This is how you pull stuff to a website, from a server which is a drive.
If you are creating a web application it would have to be on a server of some kind in the long run.