Adding collision to a spawned item via code?

I have a set of 12 items I’m spawning, I want to add collision to just one item but even when I try to add it to all I cant seem to get it to work.

Any advice would be gratefully appreciated

So there’s a way to enable it in code I believe, but the easiest way would be to just go check the collisionEnabled box on that enemy entity in the entity editor. That way all of them will spawn with that checked.

As far as code, I can’t remember exactly how to do it.

First of all, it’s probably safer to make enemy a local, just so you don’t accidentally manipulate the enemy from the previous iteration.

According to the API docs (https://tutorials.crayta.com/api-docs/#sectionMesh) collisionEnabled is a property of Mesh, however World:Spawn() will return an Entity. You’ll have to look into the docs how to get the Mesh for the enemy Entity you just spawned.

2 Likes