This should be pretty simple I think. When I want to access the player character it’s easy to just do a cast but in this case I want to rotate the mesh of an actor under a certain condition(score reaches 10):
The problem is that with this method the “Gate ref” is “none”. Setting it would be strange since the variable itself is already an instance of the gate blueprint I’m taking the function from. I tried “Cast to BP_Gate” but then I have no idea what should go in the object reference pin. I don’t get this. Please help.
What does it even mean? This sentence is contradicting. How can it be None if it’s already pointing at an instance. That’d be mutually exclusive.
the variable itself is already an instance of the gate blueprint
This is one of the most common misconceptions: the variable is not an instance, the variable is not an object. It’s just a pointer to an object that may or may not exist. if I create a bunch of variables:
It does not do much. it does not create an instance of an object. Those vars are Null; they could point to objects but you need to actually point them. SETing the value of the reference variable accomplishes that. There are other ways, like manually picking and assigning an actor from the scene.
If Gate is a BP actor, then where are the instances? How are you telling the Gate Ref variable which actor instance you mean. Imagine there are 5 Gates.
First of all, I’m grateful for you coming here and giving free advice as I’m sure most people here are, but you have a condescending attitude that is not so pleasant. I’m even considering if it’s worth it sometimes. You should try looking at a youtube video about how to be more sympathetic/empathic or at least polite to other people.
Second of all, how do I set a variable to an actor that is present in my game world? That’s what I don’t get, and I have one gate so far. If I had more I would create a separate actor for each I guess. You explain how my logic was flawed(which was quite obvious since my blueprint didn’t work), but not how to solve it.
how about using an interface? when the condition is met (i assume for the player character), it sends a message to the gate through an interface which then makes the gate open itself?
Two solutions are mentioned above. Set value to the variable. Either dynamically or flag the var as Instance Editable and pick the desired instance from the scene.
There is not enough information in your post to suggest anything more tangible - an actual example. You did not answer the question about the instances. We do not know which BP the script is in. We do not know what gates are, how they work, how they make it into the game. There is a lot of ways to set up comms, each can be cirumstantial. Perhaps you could elaborate on the setup?
@Cestarian Whether we do or do not use an interface matters little here. OP still needs a valid actor reference. They already have a ref of the correct type. It’s just not valid apparently.
A gate in my project is just an actor with a mesh that looks like a gate…so in programming terms a standard actor. I want it to be rotated by 90 degrees, i.e. opening, when the score reaches a certain number. The score is calculated in third person game mode right now. That’s where the blueprint above is located.
I’m not sure about the method to do this. Any suggestions are welcome, also when it comes to rotating the mesh around a certain point. I made an arrow for that since I recall doing something similar in another project, but I can’t recall how I used it.
As the third person game mode is not an instance in the game world, you cannot set the actor instances directly like through exposed variables (the eye icon on the right of the variable).
The only way would be to dynamically fill the references at runtime.
You can set tags on specific actors in the world like
GateA
GateB
etc.
You can the during the game mode “Begin Play” event gather all of the gate classes to an array and then either filter out the specific gate based on it’s tag or if you only need a specific gate then you can use “Get All Actors with Tag” and specify the tag to search for (for instance GateB).
Then you can assign the gathered actors to the variable references in your game mode making them valid in the process.
hi,the gate variable in your game mode isn’t a blueprint.
The blueprint is a design drawing.
The actor is an “actual thing” exciting in the scene made with that blueprint.
when you drag the blueprint into the scene,it makes an actual object.which is an actor.you drag multiple times so you have multiple actors in the scene.they are individual “gates”.
when you crate a gate variable in the game mode,you’ll have to say like “which gate should this gate variable be?”because there could be many gate in the scene .a variable can only hold a single one.if you didn’t assign an existing actor to it the variable,the variable would be invalid/empty variable.
Have the actor reach out to the game mode and set its own hard reference.
In the gate bp on Begin Play:
Get Game Mode → Cast → set gate ref
There may be a better way but if it’s just one gate ever, it’s fine. But if you must have a hard ref, you might as well just get actor of class as suggested by @3dRaven
Good catch @Everynone , the only downside to this approach would a bit more complex order of execution.
The actor would have to pass it’s references to the casted game mode , then you would need to call the specific function inside of the game mode to actually do something with the actor.
At this point delegating the whole operation to a gate manager blueprint would probably be a better solution. A sort of man in the middle.
If I remember correctly it’s an observer architecture.
You could then reference just the manager in the Game Mode and it would work as an intermediary.
Doors could subscribe to the manager through dispatchers to keep it clean.
Ouch…I know you mean well but it’s just a misunderstanding. I should have said “graph” instead of blueprint. I meant the graph in the screenshot. I know very well what I blueprint is. xD
You mean like this? I must have mistunderstood something because I can’t see how that is useful. So, my reference variable is now set as third person game mode. Hmm…
Since I only have one gate, storing it in an array is unnecessary. But feel free to show me how the graph would look for setting it, if you don’t mind.
Instead of using the get [0] function you would promote the returned array to a variable (for instance called “Gates”).
You could then access specific gates filtering the array via actor tags, array indexes or a myriad of other methods depending on your needs.
If you are going to call “AddTargetPoints” repeatedly then it would be better to cache to gate reference and then just check if it’s valid to not cause performance loss (Get all actors of class is costly), or get it during begin play and cache it and then just try accessing the variable directly.