Convert STRING name of texture to TEXTURE reference in blueprints - unreal-engine4

I have "Make Brush from Texture" node and I am able to select textures from the dropdown list in editor, but how I can set this texture field realtime from blueprint if its name is saved in the string variable (for example, "af"). Thanks.
Example:
https://blueprintue.com/blueprint/4indn35l/
SUGGESTION:
In theory, there should be an ARRAY with all loaded system textures that I can loop, compare the name of the texture one-by-one, and post the right texture to in-socket of "Make Brush from Texture".
Thanks!

You can do this by using soft object paths.
Create a Make Soft Object Path node
The Path String should be the full path of a valid texture. You can see what that should look like by right-clicking one of your textures in the asset browser, selecting 'Copy Reference', and pasting that into a text field.
Plug the result of the 'Make Soft Object Path' node into a 'Convert to Soft Object Reference` node.
Plug the result of that into a 'Resolve Soft Reference' node.
Plug the result of that into a 'Load Asset Blocking' or 'Async Load Asset' node.
Plug the result of that into a Cast To Texture2D node.
Plug the result of a successful cast into your Make Brush From Texture node.

I wasted 2 hours to discover that there's a node called "Import File as Texture 2D"
I tried to make #Rotem answer work but every casting fails, it would be useful to me because i'm trying to make the same with .wav files, and unfortunately there's no function for them

Related

Unity scaling an object when duplicating (not wanted)

I'm making a mining game, where you have a rest area, and a mine area (all of this stuff works well) but when I "hire a new worker" the main miner clones, and is put in the starting area. When I clone the main miner, the cloned miner's size goes to 6k something something.
public void moreMiners(){
if (gm.Diamonds >= gm.mmcost){
gm.Diamonds -= gm.mmcost;
GameObject newplr = GameObject.Instantiate(plr);
newplr.gameObject.transform.localPosition = plr.transform.position;
}
}
duplicating code ^
help is appreciated
Make sure that "plr" reference is the original Prefab from your assets folder and not from your scene, then what you can do is to check your original prefab inside your assets folder and see if the scale is the one that you want to have.
Also when you Instantiate an object you can parse the position too as a parameter like this:
GameObject.Instantiate(plr,position);

High CPU usage SceneKit

When I display a node from a COLLADA file, the CPU usage goes up to 100%+.
Link to pic
I am not using the simulator, I am using my actual phone. The model consists of about 80k vertices.
Here is how I load the model:
// Add Character
func addModel(name:String)
{
// Load COLLADA Model
if let myScene = SCNScene(named: "Assets.scnassets/"+name+"/"+name+".dae")
{
// Recurse through all the child nodes in the model and add to modelNode
for node in myScene.rootNode.childNodes as [SCNNode]
{
modelNode.addChildNode(node)
}
// Add modelNode to scene
self.rootNode.addChildNode(modelNode)
}
else
{
print("Error loading model: "+name)
}
}
The model is 122MB and can be found here:
Link to zip
I have tried with different models, but CPU goes nuts on each one of them. They are all about 122MB (which sounds large) and about 80k vertices.
Update
Tried to lower the poly count in SceneKit. In blender i lowered vertices from 20k to 5k (see here). But when I load the model in SceneKit the poly count is still the same (68k). I also tried converting the model and the animations to .SCN instead. This resulted in much lower file size, however the same poly count and CPU usage.
Pictures of showStatistics
I think what I need to do is lower the poly count, not so much the file size (don't think that would harm though).
Update 2
Now I actually managed to lower the poly count to about 48k. Still lagging. If I remove the texture, the CPU is much lower.
I'm not positive this is your usage issue but your method of loading your file could be streamlined.
You don't need to add each individual node from your DAE file to your modelNode. Ideally, your Collada model will have its own root node with a unique name. Just add that node to modelNode and all its children will be included. In the sample below, lyso_ribbons is the name of the root node in the DAE as well as the name of the DAE file itself.
guard let lysoRibbons = SCNScene(named: "lyso_ribbons")
else { print("Couldn't find molecule in dictionary (lysoRibbons)")
return }
let modelNode = lysoRibbons.rootNode.childNodeWithName("lyso_ribbons", recursively: false)!
All the child nodes that tagged along with the root are still accessible by name via childNodeWithName. You can inspect your DAE's scene graph in the editor window, just click on it in the navigator panel and, within the editor, click on the small square far lower left of the editor window. If, for some reason, your DAE model is lacking a root node you can create one here and move all other nodes into it. Also see: Transform and Rotate in Scenekit
You can create nodes in the left-hand panel of the editor window displaying your DAE file. Click on the + sign, far lower left of the panel. Drag that <untitled> object to the top, just under "Scene graph". Then group-select all other nodes and drag them into this new object. Give the new object a unique name. You'll notice the new node has a grayed icon meaning it has no geometry of its own.
A better way to do this is to plan ahead when creating your Collada model using nulls, with unique names, to organize your geometry nodes into meaningful sub-groups. The nulls will then be imported as parent nodes of those sub-groups. Place all nodes into one master null that will become the root for your model.

Assigning multiple assets to multiple variables on inspector

Is there a way to assign multiple assets to multiple variables on the inspector???
My case is this, I have 5 objects, those objects have a script wich have around 1200 variables used to play SFXs. When Unity compile the script I have to manually drag and drop the SFX from the assets to the variable on the inspector, or go to the inspector, scrol to the variable, click the dot and then select the SFX file from the window.
Is there a way to speed this up?
You should create a public List of Audio Sources which will appear in inspector. Lock the inspector by clicking look in right top.
Now select all the files from Project and drag on list. All files will be added to list. Now if you want a specific file you can find the file by its name for example:
AudioSource GetAudioSource(string SourceName)
{
return audioSourceList.Find(item => item.Name == SourceName);
}
Use the Resources.LoadAll method to access all the assets from the path parameter via scripting. Probably put that method call in Start. Might have to rename the files to pull the right order from the LoadAll method if they result in some alternate order.
EDIT: Here's some example code...
(NOTE: Loads from Resources/Sound/SFX folder)
For reference: http://docs.unity3d.com/ScriptReference/Resources.LoadAll.html
public class YourClassNameGoesHere : MonoBehaviour
{
Public AudioClip[] BA;
void Start ()
{
BA = (AudioClip[]) Resources.LoadAll("Sound/SFX");
}
}
I found a solution for this problem. I must say, it's not perfect, in fact, it should not be used unless is absolutely necessary.
To speed up the assign you could do this:
Create a variable
public AudioClip ma, me, mi, mo, mu;
At Start() add
ma = Resources.Load("Sound/SFX/MA") as AudioClip;
me = Resources.Load("Sound/SFX/ME") as AudioClip;
mi = Resources.Load("Sound/SFX/MI") as AudioClip;
mo = Resources.Load("Sound/SFX/MO") as AudioClip;
mu = Resources.Load("Sound/SFX/MU") as AudioClip;
After compile the public variables will be available on the Inspector as empty variables, but, on runtime the variables will be filled with the content of the folder Resources/Sound/SFX (Assets\Resources\Sound\SFX).
Why shouldn't be use unless necessary?, first, it's a bad practice; second, it's a cheap trick that comes at a price (on mobile devices it load all the resources so will consume RAM fast). In my test, all my sound clips take as much as 169 MB. On PC it's not much of a problem, but if your target is Mobile games, this is something to take into consideration. And third, on web player, ALL resources will be streamed first.
On a side note, this cheap trick ignores the way Unity handles assets. Unity force you to assign assets manually because if the asset is not use, it will not be integrated into the build. This trick force everything to be loaded and be integrated into the final build, used or no. On the other hand, if you are assign it, you will use it... right?
The answer and example given by #Jayson Ash lead me to the right direction.

Adding videos to Unity3d

We are developing a game about driving awareness.
The problem is we need to show videos to the user if he makes any mistakes after completing driving. For example, if he makes two mistakes we need to show two videos at the end of the game.
Can you help with this. I don't have any idea.
#solus already gave you an answer, regarding "how to play a (pre-registered) video from your application". However, from what I've understood, you are asking about saving (and visualize) a kind of replay for the "wrong" actions, performed by the player. This is not an easy task, and I don't think that you can receive an exaustive answer, but only some advices. I will try to give you my own ones.
First of all, you should "capture" the position of the player's car, in various time periods.
As an example, you could read player's car position every 0.2 seconds, and save it into a structure (example: a List).
Then, you would implement some logic to detect the "wrong" actions (crashes, speeding...They obviously depend on your game) and save a reference to the pair ["mistake", "relevant portion of the list containg car's positions for that event"].
Now, you have all what you need to recreate a replay of the action: that is, making the car "driving alone", by reading the previously saved positions (that will act as waypoints for generating the route).
Obviously, you also have to deal with the camera's position and rotation: just leave it attached to the car (as the normal "in-game" action), or modify it during time to catch the more interesting angulations, as the AAA racing games do (this will make the overall task more difficult, of course).
Unity will import a video as a MovieTexture. It will be converted to the native Theora/Vorbis (Ogg) format. (Use ffmpeg2theora if import fails.)
Simply apply it as you would any texture. You could use a plane or a flat cube. You should adjust its localScale to the aspect ratio of your video (movie.width/(float)movie.height).
Put the attached audioclip in an AudioSource. Then call movie.Play() and audio.Play().
You could also load the video from a local file path or the web (in the correct format).
var movie = new WWW(#"file://C:\videos\myvideo.ogv").movie;
...
if(movie.isReadyToPlay)
{
renderer.material.mainTexture = movie;
audio.clip = movie.audioClip;
movie.Play();
audio.clip.Play();
}
Use MovieTexture, but do not forget to install QuickTime, you need it to import movie clip (.mov file for example).

Canon EDSDK sample code - help to understand save file to location

I am new to the EDSDK, but so far have been very happy with the results. I have my program working just fine saving to the camera, however when I set to saveTo Host I'm unclear on where it thinks it's supposed to save to.
Everything appears to work. Callback function gets called, progress bar animates but I have no idea where it thinks it's pointing the file to.
the closest I get is finding where the #"download" command is issued, the argument to this call should be getting cast as a (EdsDirectoryItemRef)
This all seems to be coming from the EDSCALLBACK handleObjectEvent but I can't figure out how it gets constructed.
Ideally I'd like to be able to specify where on disk I want the images to go. Can someone provide some aid?
[edit]
Okay, I see the images are going into the build directory, but perhaps someone could help me to understand why. Or even better how to specify a path for myself.
When you set saveTo_Host, the image is stored on a temporary memory in the camera. The camera then triggers a DirItemRequestTransfer event that would call the callback function 'handleObjectEvent'. The reference to the image, stored in the temporary camera memory, is passed to the callback function.
Within the handleObjectEvent callback function you probably would be creating a file stream and using EdsDownload to download the file to the location on the PC (which is specified by the file stream).
When you create a file stream you need to specify a file name (the first argument). This file name determines where the image would be stored. If you just specify the file name without a path the image gets stored in the build directory. If you would like to save the file in a particular location you need to specify the file name along with its path.
Hope this helps.