How to avoid collision at spawn if mesh added after spawn

Hello There

I try to change my code to proper class handling.

before:
I safe a class reference of the picked up item in an array.
later i spawn an object of that class

Now:
I do no longer have 10 different classes that only differ by their static mesh. i have 1 class and change the static mesh in it.

As i am understanding it till now, there is no way to safe that object (a class object with a specific mesh) in any form in an array. is this right?

so i do it like this:


(i just recognized i no longer need the class reference in an array. a normal count would also work.)

and i try to spawn it like this:

The problem is:
since the “item” class has no static mesh, it never ever produces spawn-collision-feedback. i would realy like to have that.

At the moment it just always spawns an after that adds the mesh what causes glitches and bad behaviour.

Question:
How can i either define the SM before physically spawning or handle the collision detection afterwards?

Any help is appreciated
Kind regards
S

ps: this is what happens before the item gets send to the spawning BP. I take the SM out of the instanced foliage component and insert it here:

edited out typos

Hey @Slender4fun!

This is totally doable, I’m going to show you how to set your static mesh before spawn, and then you get back with us after that if you reach more issues that are not helped by that! :slight_smile:

First, on your BP_Item actor, you need to make sure it has a static mesh component (red circle) and a Static Mesh object variable(1). Then, make that variable Instance editable so each one can be different, and expose that on spawn. This will give us a pin on the spawn actor node to input static mesh.

Next, on your construction script, have your static mesh Component be set by your Static Mesh Variable. This isn’t doing anything yet, but it will be set before spawn using SpawnActor!
image

Now, when you try to use SpawnActorFromClass and put in your Item blueprint as the class (4) there will be a new pin for your Static Mesh Variable because you exposed the pin (2). Whatever static mesh you pass in here will be what the item spawns with, and that is set BEFORE spawn, so it will have the collision you need, as long as the static mesh itself has collision. :slight_smile:
image

Hope this helps!

1 Like

Excuse me sir. Are you a full time hero or did you just happen to pass by and though “hey, why not make that persons day?”

Thx a bunch! that did the trick!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.