Download

Best way to reference individual clones of the same actor

Just to give some context to my issue, I am creating an RTS building style project to learn the ropes.

My issue is with a type of actor I have on my map, in my case it’s a kind of Mineral Deposit, where you place a refinery to mine.

Each mineral deposit can only have one building placed on it at any one time. My mineral deposit actor has a boolean variable, called “In Use”. If a building is placed on it, it is set to True, and no other building can be placed on it. This works as intended.

My issue is that if I drag a second copy of the mineral deposit onto my map, then the boolean logic is shared across all of my Mineral Deposit actors. Once the variable is set to true, it is true in all Mineral Deposit cases.

Some Googling shows that this is a common issue, but I can’t quite get my head around the various aspects of this in relation to my current setup.

I could very easily do a daft workaround, where I create individual mineral deposit clones/child classes, and name them 1, 2, 3, 4, and create separate blueprints for each, but even as a beginner this sounds like a bad workaround.

Here’s my very basic logic at present:

  1. True/False “in use” variable is located on the mineral deposit.

  2. In my Placeable Building blueprint, it casts to all classes of Mineral Deposit to check if the “in use” variable is set to true before placing. If it is true, it cannot place.

  3. If a refinery building is placed on the mineral deposit, then the refinery building casts to the Mineral Deposit class and sets the variable to True.

I suspect the issue is that I am looking at this as a beginner, as my logic is currently casting to all classes of Mineral Deposit, rather than the specific "object"of that class I want to reference. In this case, I assume I need to cast to the specific mineral deposit which is being overlapped by my placeable building.

It’s just how the hell to go around setting the logic :D.

As I have not tried building a shoot-em-up type game yet, I suspect this is a basic issue easily solvable, as each actor would have a health variable, and you would only want to kill the specific actor whose health is 0 or below, rather than all of the actors of the same class suddenly dying!

Thank you for your patience with a learner :slight_smile:

You answered your own question.
Just grab the actor reference from the overlap >> Otheractor and set the boolean.

Blue variable are actual individual objects that exist in the world.
Purple are platonician Idea of them.

you know like an actual apple you can have in your hand, and the abstract idea of the apple. :smiley:
I’m sure there is a more precise definition of those concept… but well i’m no pro !

Thanks, this was helpful. I have been stuck still though on the next step of this and struggling over the past three days or so! :smiley:

I was able to get a reference of the specific actor in question and then cast to that actor’s blueprint and set a particular variable on that actor only without it influencing other actors in its blueprint. Step 1 complete. I can reference that actor in the blueprint where I set it up.

My issue is that I have three separate blueprints/actors where the reference the specific actor above needs to be re-used. In the final step, I need to use the same object reference I had stored in step 1. But no matter what I do I can’t seem to figure out working steps for this.

So I can identify the actor in question in blueprint no.1, get a reference to that actor and cast to that actor’s blueprint (blueprint 2) and change only that actor’s variables.

But the issue comes in using that same actor’s reference in another blueprint - basically using the reference I stored from the first blueprint to identify the specific actor, and calling that reference from other blueprints.

So my steps are:

Blueprint 1: Store a reference to the specific actor from blueprint2 and update the actor’s variable (which is stored in blueprint2) - DONE
Blueprint 2: No real further action needed at this point
Blueprint 3: Needs to check status of the specific actor in Blueprint 2 - the one whose reference I stored in the first blueprint. In order to do this it needs to use the same actor’s/object reference, which is stored in Blueprint 1. This is where I stumble. Plugging the reference from blueprint 1 as the object for the cast.

I have so far tried:

  1. In Blueprint 3, casting to blueprint 1 and getting the reference to then use as I see fit in Blueprint3. However this did not work for some reason.
  2. Given the above not working, I have also tried doing the same as above, but creating an actor variable in Blueprint 3 which mirrors the same name as the reference created in Blueprint 1, and adding this as the object reference instead. My thinking was that as the variables shared the same name, this might work. Also didn’t work though.

Pulling my hair out, agghh! :slight_smile:

I can cast between multiple blueprints, I can reference between multiple blueprints, but the issue for me seems to be when this specific actor reference which has been created on an event of some kind needs to be shared between multiple blueprints using a variable reference created from that event. I am sure I am doing something silly.

Any ideas?

And thank you!

Well as is aways the case, after sleeping on it the brain found a solution :slight_smile:

For reference if anyone finds this question online, and is having problems casting an actor reference/sharing that reference to another blueprint. The steps are:

In blueprint 1, create your actor reference.
In blueprint 1, cast to the blueprint where you want to also have that reference.
In blueprint 2, create an actor variable with the same name (I think same name is optional, but go with the same just to be safe).
In blueprint 1, from the cast, set the variable reference. Connect the cast to the set variable as the object target, and also connect the actor reference you created.
The reference in blueprint 2 will be the same, assuming you are setting it at the right time.