How to work with instances?

HI, I have a problem where all my instances of an actor blueprint behaves the same. And by same i mean if in blueprint a force is being applied on a condition being true then the force is applied on all the instances rather than a single one . For example in my game when you come closer to a box a force is suppose to push it further from you, and there are multiple instances of the same box on which the force is applied but out of range. now in game when playing when the player reaches near one of the instances and force is suppose to be applied its being applied to every instance thats there in the game rather than just on the instance that is in the range. or another example being the health if I am shooting an enemy instance then all the instances are taking damage. Basically all the instances behaviour is same . I have tried creating child of the blueprint and then copying the child all around the world but then its not working. I have tried blueprint interface but I dont understand blueprint interface fully so i dont know if I am on the right path or not. So I want to ask what is the procedure to work if you have multiple instances of an actor bp in the world spread around so that they dont behave as clones of each other?

Hey @Aniruddh how are you?

To be able to provide a good answer, it would be great if you could share the blueprint where you apply the forces and the actor you are having problems with!

It seems that you are getting all actors of the same class and applying the force to all of them instead of the one close to you, but I’d need more info to be able to give you a specific solution!

I’ll be waiting for your answer!

IN bp_pawn force is being calculated according to distance and direction and other stuff and the force is promoted to the variable called “char force” …IN bp_Carryboxes force is being applied (the first image) which is the class i am having trouble with….

Let me know if you need more explaination from my side though i wanted to know in general the procedure or process to work with instances of the same class as i have similar problems in the past as explained it in the question i asked. Sometimes i am able to find a work around and sometimes i called quits.

Hello again @Aniruddh

Now that I can see your blueprint, I can confirm that the problems is exactly what I thought: you are getting all the actors of the same class. But, in addition, you are also putting all this logic into you pawn instead of putting it in the box.

The right way to do this is by checking into the Box if a player is colliding with it, and then apply the force in that same place. Let me show you how:

  1. In your box, add a “Sphere Collision”:

  2. Set the sphere size as you want, but make it cover the entire box (this is the collider that will check if the player is inside):

  3. Click on the Sphere component, go to Details panel, scroll all the way down and click on “On Component Begin Overlap” to add that node to your Box BP:

  4. From the “On Component Begin Overlap” node, drag from “Ohter Actor” (this pin represents the actor that is colliding with the Sphere Collision) and cast it to your Pawn (I’m using the Third Person character here instead):

  5. After that, you can apply the force to the Box with these nodes:

Some additional comments:

A) Be sure the Box has “Simulate Physics” enabled:

B) Be sure your Box is the root component in your Blueprint:

And that’s the proper way to manage instances. With this king of approach, each box will react to the player independently of the others, as you using the specific sphere collision to check if it is overlaping with the player, and you are calculating the impulse based on “self” (which represents that specific instance of the box).

This is how it looks:

Hope this helps you understand the workflow! Let me know if you need more help with this!

Thanks for the help

1 Like