Duplicated actor

I have the same actor duplicated 2 times and I want that when I fill one, the other one does not fill, how do I do it?

Hmmm. You shouldn’t use the event tick for this because then its doing this check every frame. You should instead do this check when your count amount variable changes, much cheaper. (If this is to become a multiplayer game you’ll want to do this via rep notify)

On to your question:

  • I’m not sure where this code is occurring. But im assuming it’s the actor you want to change the mesh of.
  • there are some questions about what you’re trying to achieve specifically: for my own sanity im going to imagine you have an empty glass and each time you tap it, the count amount goes up and the the glass fills incrementally.
  • In this case, you what to be executing the code from the character (or player controller, probably better) you want to cast to the ‘glassBP’ and you want to set the Target to the specific ‘glassBP’ then just ++ (add 1) to the count amount variable in that ‘glassBP’… you see, so it depends on how you interact with the GlassBP, you could also do a line trace but that’s up to you

The difference is, instead of executing the code in the object, you are executing it on your character and casting to a specific instance of your object and adjusting its variable.

The event tick was a test, what I want to do is a warehouse, I attach a video

Show me the rest of the code, how the count amount is being set, what is happening with the trigger boxes etc. because by default the change should only happen to each instance, not all of them. So I need to see what/where in your code is causing it. However, I assume its that you are casting to your player character in your Actor and retrieving the count amount as opposed to casting to the specific Actor from your character/controller and setting it’s own instanced count amount variable

So should I do it from the first person instead of the bluepint actor?

Yeah, I had a go at recreating your issue and found that doing it from the character and setting the variable on a specific instance works as it should, however casting to the character from within the actor seemed to cause your issue

2 Likes

Everything works quite well but in the second one a static mesh fails me




Blueprint Runtime Error: “Attempted to access StaticMeshActor_UAID_7085C274E855F80F02_1085201003 via property As Pale, but StaticMeshActor_UAID_7085C274E855F80F02_1085201003 is not valid (pending kill or garbage)”. Node: Set Static Mesh Graph: EventGraph Function: Execute Ubergraph BP First Person Character Blueprint: BP_FirstPersonCharacter

You maybe want to add some more IsValid? Checks before set static mesh and destroy on your last screenshot - the same as what you did in your first screenshot

with is valid I don’t get the error but the set static mesh still doesn’t work

That tells me there might be a casting error, try to add some print strings between each action and see where it fails, im away from my computer atm but ill write how I would make this code and send it to you later

What I don’t understand is why the first time it goes well and the second time it fails.

First step is to understand where it fails, add some print strings (particularly where your condition returns false) to identify where it goes wrong

As I was testing, the cast fails

ah probably because you are promoting it to a variable, therefore its still trying to set the static mesh of the 1st referenced object, not the second one.

yes, they are variables


image

yeah but where do you cast to as pale and make it a reference, begin play?

If so what is happening is that your AsPale reference is referencing the first instance (which works) but then when you try to do the same thing for the second instance (you are still only referencing the first instance, so it fails, returning that the reference is invalid because you already destroyed it)

A quick solution is to set whichever instance you interact with as the AsPale Variable as your first action wherever your code to interact is

1 Like

It worked, you are amazing, thank you very much for everything

1 Like

I only added one thing and it stopped going again



it fails in the second but the cast does do it but it does not destroy what it should destroy

what did you add?