x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Casting diffuclty: What exactly am I doing wrong

Hey all, I hope everyone is well.

I get most types of casting, like when something crosses a trigger box, but I've been struggling with figuring out how I'm supposed to target cast. I've made a serious effort to learn this and I'm just missing something. Here's what I feel like should work, but isn't.

On event beginplay, I spawn a UMG menu, but I do it from my main actor. It's important that the menu construction happens after certain things with the main actor. I assigned the menu to a widget variable called "Start Menu Widget". alt text

On event construct, I have the start menu spawn some menu music. alt text

I spawn an options menu from the start menu when a button is hit alt text

And finally I want to be able to turn off music from an action in the options menu. According to the UE4 documentation located here, I believe I should be able to do that by target casting. Below is my attempt. alt text

I would REALLY appreciate anyone willing to advise me on what I've done wrong syntactically. I have been at this for a very long time, and my failure to make this work is stressing me out. What goes on the other side of "target". Am I even close to doing this right? PLEASE, anyone, at the very least, point me to reading material that is clear, although, actually telling me how to solve this specific problem would just be dapper.

Product Version: UE 4.21
Tags:
more ▼

asked Jan 10 '19 at 12:02 AM in Blueprint Scripting

avatar image

geekTechnique
83 2 6 12

avatar image ThompsonN13 Jan 10 '19 at 01:14 AM

lets start with the error your getting. this error basically says that the bp that the script is in does not inherit from the gamestartmenu class. im guessing you have that particular script in your options menu yes? if thats the case then you need to get a reference to your start menu widget. what your doing now is trying to change a parameter in a class that doesnt have that parameter, its like pushing a button on the toaster to change the tv channel. so get a reference to the appropriate widget (game start menu) and you will be golden. how you get the reference will be the main question here.

if im correct in that the script shown is in the options menu and that menu is being spawned from the start menu then the solution if actually pretty easy. first i would create a variable in the options menu called lets say "StartMenuWidgetRef" and plug it into the cast node instead of target node you currently have. then in the start menu drag off where you set "options menu widget" (off the blue pin) and search for set "StartMenuWidgetRef". now for the input on this node you just need to have it set to self. that should solve your issue.

hmmm the issue itself can be a bit hard to explain so the explanation may be hard to understand but the basic idea is that the node you currently have is expecting a reference to certain class but the class youve provided isnt the one it needs.

avatar image geekTechnique Jan 12 '19 at 07:51 PM

Sorry for my delayed response, I've been very busy the past few days and I'm just now able to work on this. First, let me say thank you so much for taking the time to help.

I've followed your steps the best I can, and the cast is failing. I will detail exactly what I did, and shortly after posting this, I will follow the other answers in a similar way.

if im correct in that the script shown is in the options menu and that menu is being spawned from the start menu

Yes, that is correct

first i would create a variable in the options menu called lets say "StartMenuWidgetRef"

Done. To be specific, I made this variable a user widget- object reference and I made it instance editable, and expose on spawn (I tried both with and without expose).

"StartMenuWidgetRef" ... plug it into the cast node instead of target node you currently have

This is where things fall apart for me. While I don't get a compiler error, when I tested this, the cast always fails.

alt text

Anyway, I followed the rest of the steps in order to see if things would work.

in the start menu drag off where you set "options menu widget" (off the blue pin) and search for set "StartMenuWidgetRef". now for the input on this node you just need to have it set to self.

I tried following that very carefully and got this error. alt text

Finally, I was able to get it to compile without errors by doing this (although I'm sure it is wrong). That still leaves the casting failure from my first image. alt text

Given the level of detail in my response, I feel like you should be able to identify what exactly I'm messing up here. I know I said thanks already, but thank you again for going through all the trouble.

avatar image the_batch Jan 10 '19 at 02:03 AM

Adding to what @ThomasonN13 wrote, in case it helps to see it described another way:

The node that is giving you errors is basically telling you that 'self' (the containing blueprint) does not have a variable called 'Start Menu Widget'.

According to your third paragraph, right above the first picture, you say you're creating (and saving as a variable) your 'Start Menu Widget' from your "main actor."

You somehow need get access to that 'Start Menu Widget' variable from your options menu blueprint. Then you should be able to cast with no trouble.

There are many ways to do this, but maybe the easiest is to try to access your "main actor" from the options menu and grab its 'Start Menu Widget' variable, assuming it is public. Give something like that a try and let us know how it goes!

avatar image ThompsonN13 Jan 10 '19 at 02:09 AM

hmmm i forgot about that main actor bit. you could just save a reference to that somewhere like the game mode or the main actor could be the game mode. that would be good since the game mode is easy to reference.

avatar image geekTechnique Jan 12 '19 at 08:11 PM

Hey Batch, Thank you so much for trying to help me. Sorry for my delayed response; I've been quite busy.

You somehow need get access to that 'Start Menu Widget' variable from your options menu blueprint.

That is exactly correct.

access your "main actor" from the options menu

But how? My main actor (I named stack spawner) is made from a blueprint class. I dragged that blueprint class into my viewport, and when I hit play, the level loads and it is there. It's scripts fire like they should, and it works, but that means I don't have an opportunity to assign it to a variable during instantiation, meaning I don't know how to reference that actor via blueprint. Like, what if there were 2? how would I reference one specific actor from blueprints like that?

I'm sorry if I'm missing something obvious, but I have put a lot of effort into understanding what I'm supposed to do, and I'm trying to follow what you're telling me. I mean, I get it, I just don't know how I'm supposed to implement it.

Please see my other reply to Thompson for detail on what I've tried.

Thank you again.

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

So your hierarchy is as follows:

         Main Actor 
                 UMG Menu (Start Menu)
                           Menu Music
                           Options Menu

And you want the Options Menu to turn off the music the Start menu created. So what I would do, is create a variable of type "UMG Menu" within the "Options Menu", set it to instance editable and expose on spawn. Then when you spawn the options menu FROM the UMG Menu it will ask for a reference object pin for this "UMG Menu". You can simple give it a reference to "self" since the UMG menu will spawn the options menu. Now from the options menu, you will be able to drag out this "UMG Menu" reference and access the music variable you created. Once you have the music variable you will be able to stop the sound using a button in the options menu.

more ▼

answered Jan 10 '19 at 05:53 AM

avatar image

Nebula Games Inc
4.1k 24 9 14

avatar image geekTechnique Jan 12 '19 at 08:29 PM

Hey there Nebula Games, thanks so much for taking the time to help.

So your hierarchy is as follows: ...

Yes, your interpretation of my project is accurate.

create a variable of type "UMG Menu" within the "Options Menu"

I do not have that option. Similar options for me are

-widget blueprint

-user widget:

  object ref

  class ref


-widget

-game start menu (in ref to my menu I made)

  object ref

  class ref


I would greatly appreciate some clarification, because I really want to get this, and I feel like your explanation is clear, I just don't have that umg menu reference. Thank you again.

avatar image Nebula Games Inc Jan 12 '19 at 09:21 PM

Your main actor creates the first widget (UMG menu) which you actually called "game start menu". So in your options menu, select the button in the details panel on the left to create a new variable. It will default to a boolean. Name it "start menu ref". Then change its type to "game start menu" and make it an object reference. Then check the box for instance editable and expose on spawn. Now you have an empty container to hold the "game start menu" widget class. And because it was exposed on spawn when you create it (the option menu) from within the game start menu it will be an exposed pin on the widget creation node. And you simple drag off and search for "self" this will create a reference to the game start menu widget that spawned the options menu. And from there you can access game start menu functions from the options menu.

avatar image geekTechnique Jan 12 '19 at 11:07 PM

Let me just say, I've been trying to wrap my head around this for weeks. Thank you. You have no idea the amount of relief this has brought me. Your steps worked perfectly for me. I appreciate everyone here that's tried to help me, but this last message did it for me. I sincerely appreciate the assistance.

For anyone interested in what worked see below-

This is written in my options menu- alt text

And this is written in my start menu- alt text

avatar image Nebula Games Inc Jan 13 '19 at 01:11 AM

Haha no problem. Glad you got it working

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question