I’m working on a Arch Viz project and as i’m pretty new to blueprints and I can’t figure out how to spawn an actor : I want to spawn the eau_baignoire geometry cache in my bath tub by clicking on my third UI button (first and second are changing bathroom material and it works fine) :
im guessing your pretty new to scripting in general. the issue comes down to getting a reference to the correct actor. your current method is to get all of class which is a poor way to go about it and its very inefficient. it would be much better to have a specific reference to one definitive actor. to that end how are you creating the widget? you could for example have a variable in your widget which will be the reference to the actor, then when you create the widget you set the variable at the same time. of course thats if your creating the widget from the actor you want to target or can get the reference from there.
really though for your case you may not even need to spawn an actor. it looks like your just trying to have the water show up when you press the button right? if thats the case then you could just have the water as part of the bathtub actor and toggle the hidden in game of the water, basically toggling the visibility.
You’re right I have some experience in art but not my road in scripting is just beggining… I spent the day trying every forum posts solutions I could find so this is the last system I could try. I have some issues understanding your answer (what reference and target must be in my case).
What do you mean by one definitive actor ?
I though of toggling the visibility but my water is a geometry cache animation : it fills the bath tub. Wouldn’t it show at random state if it was unhidden at a random time? My simple goal is to create an interactivity (filling the bath tub) with the third button. Thanks ThompsonN
a reference is a way to refer to something so a way to define / identify it, so if i wanted a reference to you then i would need your name and defining characteristics. in terms of the current topic the reference would be the specific instance of the actor, so if you had three bathtubs it would be a way to say which specific one. thats also what i was getting at with the definitive actor bit. lets say again you have three tubs in the level and you use your current system to get all of class then run a for each loop, that would result in every tub in the level being filled. if instead you have a reference to a specific tub then you can target that one and say i want only that tub right there to fill.
below is two examples of the type of situation i mentioned. as you can see with method 1 we create the widget then we set the variable contained within it. method two is for if you have a widget component in the actor, it shows how to identify the widgets class then set the variable within.
i guess the toggling of vis wouldnt really work in your case since its a animation, i didnt realize it was an animation before.
I’m sorry for not understanding everything you tried to explain. I don’t understand why you propose to place nodes in the character blueprint and not in the third button settings (function “Bathroom Set C”). Here’s a recap of my blueprints :
-Bp_bathroom (the static mesh to change materials)
-Eau_Baignoire (the geometry cache water blueprint)
-UI_bathroom (my buttons)
-TargetPoint_eau (the targetpoint i want my water to spawn at)
Again, all i need is making the water (Eau_Baignoire blueprint) spawn at the TargetPoint_eau location.
i was working the in the character bp since i dont have a bathtub actor, basically it was the easiest location for me to create and test the script needed. all the scripts that i showed would actually be in your bathtub/bathroom actor or wherever your creating the widgets.
Couldn’t set method one
you need to drag off of the return pin of the create widget node then search for the variable that your created in the widget. as you have it now you created the variable some other place and thats why you cant set the target, basically your trying to set a variable in class X but the reference your plugging in is class C.
With method 2 the bathroom ui does not work anymore (not clickable)
i didnt Test if it was clickable or not, i only proposed this method in case you were using a widget component already. I just went ahead and recreated the example and tested it and it works without issue and is clickable.
When deleting method 2 (keeping only the new nodes in bp_bathroom > the third vutton function)
no idea what your saying with this one.
get this error when clicking the third buton :
access none errors usually occur when you try to get a variable whose value has not yet been set.
ok so lets make things simple first where are you creating the widget for your buttons? since i didnt know i proposed multiple examples but if we can clear that up i can be more specific. next is the bathtub its own actor or is everything in your bathroom included in those two meshes in the bp_bathroom?
alright now to clear up another thing, i was working under the assumption that the bathtub was its own actor, given that i was making a solution where you spawn the water based on the bathtub actors location. you however are using target points in your pictures which is a matter that is very much different. I like to keep all functionality in the actor, whereas your use of target points would probably need to use the level bp.
where are you creating the widget for
They are in my UI_bathroom blueprint.
is the bathtub its own actor or is
everything in your bathroom included
in those two meshes in the
Bathtub and the furniture aside are in the Bp_bathroom blueprint. The water is its own actor (Eau_Baignoire blueprint) but i gonna add it to the Bp_bathroom blueprint. Let’s start like that !
i was making a solution where you
spawn the water based on the bathtub
actors location. you however are using
target points in your pictures which
is a matter that is very much
Indeed I used a TargetPoint because the water needs to be a bit higher than the bathtub. But i will delete the TargetPoint and move my water in the Bp_bathroom blueprint with the bathtub and the furniture.
ok im gonna break this down as if you were starting from scratch, a-z, barney style so to speak.
first create new a widget actor Named W_BathtubButtons. next open the actor and add in a button component. click the event graph button near the top right. in the my blueprint tab on the left locate the variables section and click the + icon to add a new variable. name this variable WaterLocation. with the variable selected go to the details tab (bottom left) and ensure your name is correct, then change the variable type to vector as shown, make sure it has the little capsule next to it showing its a single variable. next select your button in the variables tab and then in the details tab look for events section locate where it says on click, click the green button with the + icon that is next to on click. that will create a on click event in the graph. now drag off the white execution pin on the on clicked node and in the search menu that comes up search for “spawn actor from class”, this will create the node and attach the execution pin. now right click the orange spawn transform pin and select split struct pin from the popup menu, this will break the transform into its constituent parts. next hold down control on your keyboard and click and drag your WaterLocation variable from the mybluprint tab onto the graph. drag the yellow pin on the newly created water location node to the spawn transform location pin. compile and save
for the next step go back to the level editor window and create a new actor, name it BP_Bathroom, and open it. click the add component button at the top left, then search for widget and click it in the list. repeat the process but instead of searching for widget search for scene to get a scene component, name it scene_waterSpawn. repeat once more to add a static mesh which will represent you bathtub. click the viewport tab and in the preview viewport window (area at center screen) adjust the placement of scene_waterspawn to where you want your water to be spawned. click the event graph tab to open the event graph. locate the event begin play node, if you cant find it right click the graph and search for event begin play and click it in the list. next select your widget and drag it onto the graph to get a node reference to it. drag off its blue pin ans search for get user widget object and click it in the list. drag off this new node and search for cast to W_BathButtons. next drag off of the as w_bathtubButtons blue pin and search for set WaterLocation, this is context sensitive since we are searching for a variable located in another actor ( we have to drag off the pin and search or it wont show up). that will have created a set node, connect the execution pin from the cast node to the set node as shown. next select and drag your scene_waterSpawn component onto the graph. drag off its blue pin and search for get world transform and click it in the list, (this will get the components location in world space). drag the yellow pin from the get world location node to the yellow pin on the set waterLocation node. next select the widget component in the components tab. then in the details tab look for the user interface section. here set the space option to screen, this will make the widget always face the screen of the player. then set the widget class to W_BathtubButtons.
go back to the level editor and place the BP_bathroom actor into the level and press play to test.
i realize that was probably overly in depth but o well. also please stop posting your replies as answers, it makes things much harder to follow for others later. use the reply button instead, if the reply button doesnt show up then you are probably not logged in. to log in click the login button at the top right or if on mobile you may need to open a dropdown menu via a button near the top.
Hello ThompsonN13, Thanks much for your help. It did a bit different than your solution because I wanted to use my existing bathroom buttons UI (and use the third button) but I could manage to make the water spawn thanks to you :
I kept the water as an actor :
Now, to go further and make this fully interactive, I would like to :
-Add an animated effect of water flow from the faucet
-Forbid user to spawn unlimited water in the bathtub until bathtub is empty (see below)
-Reverse the geometry cache animation at its end so the bathtub get empty.
-Play a different sound when the bathtub fills out
This series might be helpful for you if you are just starting out so you have a foundation of understanding of the basics of blueprints like references, casting, functions, event dispatchers etc It will help reduce the number of questions you have and the need to explain the explanations themselves.
As for your final questions about playing a sound when the tub is filled or emptying the tub/not allowing too much water to spawn we would need to know how this animation is working. If it is a simple animation node you use for it, it should have an option to “reverse” animation. To stop users from spawning too much water you can use a boolean variable that prevents water from being spawned multiple times. Call it “Has Spawned Water” set it to false and use it with a branch node before the spawn water function. Hook the false pin up to the spawn node. After you call that function set it (the boolean) to true. This will prevent more water from spawning until you set the variable back to false perhaps after the tub is emptied.
You’re right. Thank you so much for this, i will learn with those tutorials.
About the water geometry cache animation, I’ve seen in another post (by Draise):
You can now load Alembic cache files
as “Skelaton” (and define frame range,
etc) which in turn creates an actor
and an animation file. With the
Sequencer, you can load the actor,
then load the animation track - and
now with this you can retime and edit
the alembic animation cache.