CastTo Actor Quandary

I am lacking some information and understanding concerning the CastTo system. There are examples in the docs, but they stop at gamePlay Mode, and PlayerCharacter and SaveGame.

I’m looking to do a castTo an Actor, and access a bunch of the variables that I have there (and references to actors it spawns in game).

Here is my CreateWord4 Actor. One of the things it does is generates my pickups, and then sets a reference to them (if I’m doing this right).

53743fd56fe84cf50aa2a6006b15413cf35cb572.jpeg

This below is my Blueprint for a collider object, that is listening for the pickup in question above.

When I run this in game, the pick intersects and there is definite difference between something that doesn’t have the right tag, however it stops the action when it gets to the CastToCreateWord4 node.

10a9d1749e5448b1e2dac6f69154ac4de040d1f2.jpeg

I have tried about 1000 variations on putting this in, but I just don’t have some vital piece of information about how the CastTo is working with Actors and then how to get that information.

Notice I am using the CastToPlayerCharacter before this in the script and this portion works just fine, because I can easily do a GetPlayerCharacter function call to attach to the object here.

I’ve put so many hours into this, and it seems like it is something that should be super easy that I’m missing, and I’m sorry but this isn’t well documented enough to make this easy to understand for anything outside of the PlayerCharacter, game Mode, and SaveGame, two of which I use without problems already.

can i get some eyes on this?

the cast to looks correct, Other Actor must simply not be a createWord4.

Try using the Get Class node with the Get Display Name node and a print string node to see what Other Actor is overlapping the Collider_Box. (Really checking the class would work rather than checking if it has a tag anyway).
As Dividual said, it probably just isn’t createWord4.

What do you want to happen, and what is happening? If you put a print string node after the cast instead of destroy actor, does it print?

It does not print no. The highlight lines that show the action during gameplay, show it stops at CastTo and won’t go further. so yes I think that sounds right. The connection from the “OtherActor” doesn’t equate to CreateWord4 (if that’s what you meant by that ).

The ActorHasTag works, because the branch can distinguish between the right object and wrong object but doesn’t get past the CastTo.

I have other things i need to do after the CastTo, but I just left all that off right now while i figure out how to make the CastTo correctly see an actor rather than player or mode.

okay I’m trying to use GetClass or GetDisplayName but I’m not sure how you think I should connect these. When I try to route into the CastToCreateWord4 Object input, it gets rejected because they are not an object or an interface (the node).

How do people generally get the variables from other actors? This would seem to be a very needed thing, but i’m not finding enough info.

thanks for the feedback so far, it’s very appreciated. when you work alone you start to feel like you’re going crazy after trying something in 1000 variations. That’s why i try to check the forums in the mornings and see if can offer help to people where I feel I can, because i know that feeling of isolation. I’d like to say I’m the Mark Watney of working in my studio, but I’m betting a lot of indie developers are on the same um… planet.

Try like this for example:

Casting like that is a common way to get variables yes, though sometimes you wouldn’t need to cast. If your variable is already of that type you want, there would be no need to. You can think of “Cast to” as meaning “treat as”.
OnOverlap is returning Actor, so you have to cast it if you want to call functions specific to your class on it etc.

exactly like you are doing it, except they have the correct actor and not some other actor. :stuck_out_tongue: what i meant earlier is that you are not overlapping with a createWord4, but rather with a totally different actor.

Dividual that is correct. I am not overlapping with createWord4. CreateWord4 is actually a Blutility Actor that generates a bunch of objects in my game, but it generates the objects I need thus saving the variables for them (which yes, could be the problem here).

Mind you i was placing these things (word puzzles) by hand previously, but setting up one word and connecting the objects I put in the game to a new set of nodes that would turn things on and off. (side note : I know this sounds strange, but it’s an adventure game for kids who have trouble with spelling - in particular dyslexic kids like my son).

So the original blueprints to turn things on and off was all working as kids solve words. But it takes far too long for me to set up, and as words (and phrases) get more complex it takes increasingly long time to setup words and test. So the goal is to be able to auto-generate by typing in a word (using Blutility) it gets the different letters I need, both clear and solid, pickups and colliders (each letter class has it’s own collider class).

So I’m plugging in the blueprints that I was putting int he game level, into the ColliderClass. This is CLS_A_COLLIDER for instance. It’s looking for the names of the pickup, and whether the tag matches so it can do what it does. It’s possible to set this up in the gameLevel Blueprint editor, but time consuming manual work that I’m trying to bypass by having the collision logic in the actual collider as a blueprint class.

I hope that makes sense.

If this goes well it would shave off thousands of development hours just plugging in words so that i can make a better game. At the rate I’m going with out this utility i’m just too slow to make steady progress. Setup and testing one word takes me between 30-60 minutes. So to set up hundreds of words (and the thousands i have planned will take up more game dev time than i can afford to put into this).

Anyway, all that to say the createWord4 sets up the letters I need, and then I need to access those letters through variables (using CastTo) so that I can

You can’t arbitrarily cast like that, youļl need a reference to CreateWord4 in the blueprint.

I’ve not used Blutility so I don’t really know what you are doing, but create a new variable of type CreateWord4 in Collider, then you need to set that to an instance of CreateWord4, again, I don’t know how blutillity works, so I can’t say how you would do that.

But if both these actors were placed in a level, and Collider had a variable of type CreateWord4, you would be able to set it to the placed instance in the details tab of collider, in your level. After doing this, you wouldn’t need to cast as it would already be of that type

Mosel3y

I see what you are saying too. I see it print the class out to the gameplay screen. I think maybe i can even bypass the need to do a castTo if i can identify the name of the object that I just collided with, that would simplify things.

Is there an easy way to get the name of the object that I triggered this collision with and then feed this though? I tried Get ObjectName function call, and it will print to screen, but if I try to feed it through the object input of the Destroy node, well… i can’t connect it actually. Destroy doesn’t recognize it.

I don’t seem to be able to feed GetObjectName into a set variable node either.

Object name is a string, not an actor, so yep itš no use for that. What object is colliding, your pawn?

Presumably, you want some action to take place when your pawn collides with this object, if I’m understanding. And at that point, you want to do something with CreateWord4.

Try something like this:
I have a blueprint actor called collider which has a collision box. I have another blueprint actor called CreateWord.
I create a variable in Collider with of type CreateWord, its an object reference, I click the symbol highlighted there to make it publicly editable.
This means you can change it when you place an instance in your map for example.

I now place both in the level, at this point I can select the collider actor, and set itš reference to the CreateWorld actor below

  1. is the collider and 2. is the CreateWorld. Collider now has a reference to that object, it doesn’t have to cast it to anything, since it is that type already.

Now I can call whatever fucntions I want on CreateWord, or get/set any variable when an actor overlaps the collider, like this:
I drag out my CreateWord variable, and I have access to itš functions and variables.

in the collider actor:

If I’m understanding you right, this is something like what you need to do, and yes you don’t need the cast for this

Mosel3y

I got what you were saying above. Yes, once the variables are exposed in the details panel I can expose them. I just tried that, and it worked. I didn’t have to name it createWord, it could be anything but I had already set variables up for the letters. So I chose the one that I had been looking for all along.

So that was incredibly helpful, i just didn’t use the CastTo at all. I still feel like there is something missing in my understanding of CastTo that I was hoping to get past this time round, but at least this puts me back on track.

One last question, the last post I put out, I was saying one of the things I’ve had trouble doing is making it give me the name of an object that collided with the Collision object, if I could do that I would be able to use multiple letters for a puzzle more easily. Right now I have to accommodate an either or scenario to account for letters, which is makes my script difficult to maintain as well.

otherwise thank you for your insights and for setting me straight about castTo in this instance.

-finn

MoselBy

I follow what you’re saying above I didn’t get that by making this reference it meant having access to all the variables when they overlap like this. This is something I wasn’t getting from all the demos and reading I’ve done.

However, like Dividual pointed out, the collision will not actually be with createWord but rather with one of the objects that it created, which is why the information is not coming through during the collision call?

Below i the blutility page that is up. It’s not far off from what we are doing except for one thing. The bonus of creating with Blutility is that i can “RUN” the blueprint outside of gameplay, so that it creates what i want, (could be anything). For me it sets up about ten objects precisely (more depending on how long a word is and what is missing in the word), at the click of a button. You could theoretically setup an entire city or maze etc like this too in the editor in one go. I think it’s really a valuable tool.

thanks for the help and for clarifying with diagrams.

Yep cast word have worked here only if the object colliding had actually been of that type. BeginOverlap returns an actor, a reference to whatever object it has collided with, and if you knew that that object was a CreateWord, then you could have cast it to createword, so you can treat it as that type and access functions and variables specific to it. In this case, the actor colliding just wasn’t a createword, so it couldn’t be cast to it.

You would only really use cast if you know itš going to work, i.e you know what you are casting to and from.

What is the print string of of get name printing? I don’t understand exactly what you want to do with display name value. You can promote the result to a string variable, but if you want a reference to the actual actor, just promote the Other Actor and set it. You then have an actor reference to whatever collided. Note you can also compare the collided actor to an object using the == node. What object do you expect to overlap your collider, is it always an object of a certain class?

edit: jsut saw your post, ok, so all the objects that may overlap your collider, are they different classes?

i’m gonna try to explain casting a bit

imagine you had a class hierarchy where you have a base class called Vehicle, and two derived classes called Car and Airplane. When you get a reference to a Vehicle, the program doesn’t know if it’s a Car or an Airplane (or just a Vehicle). But if you as the programmer know that the referenced Vehicle is actually an Airplane, you can use Cast To Airplane and get a reference of type Airplane (if you were right and it really was an Airplane).

Now if the Airplane class has a function like Fly or whatever, you can call it on the Airplane reference, but couldn’t have called it on the Vehicle reference. Because your program didn’t know it was actually an Airplane before you casted it.

You were trying to cast a reference to one object to a totally different object, which is not possible.

"I don’t seem to be able to feed GetObjectName into a set variable node either. "

What GetObjectName returns is a string. If you want to feed that into a variable, the variable also has to be of type String.