How could I load a Static Mesh from external folder? - unreal-engine4

I'm learning UE4 C++ Development and I have a idea but I don't know if that is possible to make. I have a folder on my WAMP SERVER for exemplo ( C:\wamp\www\staticmesh\My3DModel.3DS ). My idea is create a button on my UE4 widget and when It's pressed it import my Static Mesh from my folder to my currently scene. It's possible ?
OBS: because my game will be too heavy, so I thought I would import the static meshs and put in the scene in real time, without building next to the game. If you know another solution or any idea it will be welcome. **
Would Somebody be willing to helping me step by step How could I implementing that code below ? It's very very important to me, because I'm learning UE4 C++.
// Load Static Mesh From Path
static FORCEINLINE UStaticMesh* LoadMeshFromPath(const FName& Path)
{
if(Path == NAME_None) return NULL;
//~
return LoadObjFromPath<UStaticMesh>(Path);
}
Thank you so much for any answer.

You are asking a bit much if all you did yet is draw that sketch.
If you did more already please share the information.
I recently answered what I could identify as core part of your question tho - how to get the mesh from local drive into ue4 -
https://stackoverflow.com/a/41753091/5196012
This also features the link to the wiki where your code sample seems to come from.
You are missing the template the person has on the wiki
//TEMPLATE Load Obj From Path
template <typename ObjClass>
static FORCEINLINE ObjClass* LoadObjFromPath(const FName& Path)
{
if(Path == NAME_None) return NULL;
//~
return Cast<ObjClass>(StaticLoadObject( ObjClass::StaticClass(), NULL,*Path.ToString()));
}
Since no one knows what selectionstrategy you have I guess it will be some standard file browser dialog returning a file handle...
All you would need to do then is to call your function in the widget button "on pressed" event.

OBS: because my game will be too heavy, so I thought I would import the static meshs and put in the scene in real time, without building next to the game.
That is not possible. The moment you import a static mesh it will be saved as a .uasset file in your content folder.
How big are your meshes and how small is your disk that you cannot import them?
If you absolutely do not want to import any assets you can generate your meshes at runtime with this plugin: https://www.unrealengine.com/marketplace/runtime-mesh-component
Note however that you lose a lot of extra goodies and optimizations with that approach.

Related

Struggling with Mobile build on phone, looking different on phone and Pc

Firstly I'm still fairly new to coding, saw people making games and fell in love with the idea of making your own game. So the past few months I've been learning unity tutorials and practicing basic games. I've come so far to be basically done with my first game. Everything is ready and I want to load and post it on playstore, but there's one last issue. When I run it on Unity on my pc it looks perfect but I loaded it onto my phone and the UI and some objects is either not showing or looking different than on the pc.Example1Example2Example3 These are examples of my problem. The IMG above is the way it should look like and the one underneath is how it shows on my phone when loaded.
It doesn´t look the same, due to the different resolutions.
Try to use a Canvas Scaler component. Set a reference resolution and the mode how you want to scale it.
If you want your UI elements to be anchored to the center/top/left etc. you should also set the anchor points. Here is a good Tutorial
A good way to instantly check the result is the "device simulator" It is a unity package
That's because of your Canvas settings & your UI GameObjects Anchor. But I think the easiest way to solve this for you - because you don't have that much experience about it - is to separate canvases for mobile & pc. This is the code:
private void Start()
{
if (Application.platform == RuntimePlatform.WindowsPlayer) // If your game's running on android
{
pcCanvas.SetActive(true); // Use PC designed canvas
mobileCanvas.SetActive(false); // Disable Mobile designed canvas
}
else // Your game is running on mobile
{
pcCanvas.SetActive(false);
mobileCanvas.SetActive(true);
}
}
Add this to a GameObject, Design 2 Canvases & assign them to script. (This will be a litte complicated, but will work) This link for more info
But if you want to use 1 canvas, you have to set its settings & its GameObjects anchors.

Unity and Google's Blockly library integration

For my undergrad final project I want to develop an educational game for teaching basic programming so I want to provide them some easy drag'n'drop visual programming editor like in this code it but i have no idea how to do this i'm new in unity and i did a lot of search in google but i didn't get it ( i'm quite loste ) .so please can any one help me in these and give me a clue so i can build on it. thank you for your help
this is a example for my game design expl ( i want to move the player by drag and drop move right , move up ,move forward ......). I home my idea and question are clear
A few months ago I developed a project very similar to yours. I recently extrapolated a library from this project and published it on github. the library is called blockly-gamepad 🎮 and allows you to create the structure of a game with blockly and to interact with it using methods such as play() or pause().
I believe this will greatly simplify the interaction between blockly and unity, if you are interested in the documentation you can find the live demo of a game.
blockly-gamepad 🎮
live demo
Here is a gif of the demo.
How it works
This is a different and simplified approach compared to the normal use of blockly.
At first you have to define the blocks (see how to define them in the documentation). You don't have to define any code generator, all that concerns the generation of code is carried out by the library.
Each block generate a request.
// the request
{ method: 'TURN', args: ['RIGHT'] }
When a block is executed the corresponding request is passed to your game.
class Game{
manageRequests(request){
// requests are passed here
if(request.method == 'TURN')
// animate your sprite
turn(request.args)
}
}
You can use promises to manage asynchronous animations.
class Game{
async manageRequests(request){
if(request.method == 'TURN')
await turn(request.args)
}
}
The link between the blocks and your game is managed by the gamepad.
let gamepad = new Blockly.Gamepad(),
game = new Game()
// requests will be passed here
gamepad.setGame(game, game.manageRequest)
The gamepad provides some methods to manage the blocks execution and consequently the requests generation.
// load the code from the blocks in the workspace
gamepad.load()
// reset the code loaded previously
gamepad.reset()
// the blocks are executed one after the other
gamepad.play()
// play in reverse
gamepad.play(true)
// the blocks execution is paused
gamepad.pause()
// toggle play
gamepad.togglePlay()
// load the next request
gamepad.forward()
// load the prior request
gamepad.backward()
// use a block as a breakpoint and play until it is reached
gamepad.debug(id)
You can read the full documentation here.
I hope I was helpful and good luck with the project!.
EDIT: I updated the name of the library, now it is called blockly-gamepad.
Your game looks cool!
For code-it, we are using Blockly as the code editor. The code is then executed by a Lua interpreter inside the game. You could do something simpler: make one block type for each action, like MoveForward etc. and have them generate function calls like SendMessage('gameInterfaceObject','MoveForward'). In the game you need an Object that listens for such messages from the website.
Here's how your game talks to the website:
https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html

Instantiate 3D models from an external folder

I have small project that I am creating to learn a bit more about Unity.
In this project I have a lot of 3D models, and I need to use only some of them. I am using external text file that the program reads when executed, in order to tell it which models to load.
For example, in the text file I can write:
Hunter, CandyHouse
and the program would instantiate those 2 models only.
My problem is that I don't want to save all the models in the Resources folder and load onluly those I need, because that would increase my program size drastically. So what I want to do is to save the models I need next to the text file and instantiate them. But I don't know how to access them from Unity.
I have found the WWW class in some answer, but they used it to load textures, when I tried to load Maya file with it, Unity just stopped responding.
Is there anyway to do it¿
Use model make a prefab.(This can decrease draw call when you need many model in scene.)
Use this prefab make a assetbundle.
put this assetbundle in your url(this could be a remote server url or a file url.Note that iOS/Android may have problem on permission of read/write).
And use the code follows to load.
WWW www = new WWW("url");
yield return www;
GameObject obj = Object.Instantiate(www.assetBundle.Load("ModelName")) as GameObject;
We could also use LoadFromCacheOrDownload,the asset will be save speficy location.So no need everytime load from web.

Unity3d + Facebook SDK - Switching Scenes

Before trying to do anything stupid I wanted to ask the experts: what are the best practices on the scenario of switching scenes?
Does Unity3D retain the information of FB.Login() on the first scene forever, or do I need to initialize FB on every scene I loaded?
Sorry to ask before testing it, I am away from my dev machine and really curious!
I made some research and found out that if we create a static class, with a static property it will remain the same as long as the game runs.
So I created 1 static class with a static property of my FacebookUser class and it remained active while switching scenes.

Use multiple components in Flash AS3 - iPhone app

First of all: Happy new year!
I have a problem with Flash CS5.5, AS3. I have two ScrollPane Components in my document. They are both in another scene and the (instant)names are unique. But it isn’t working properly. When I go to the other scene with the second ScrollPane I get an error & it starts to flicker.
My error:
TypeError: Error #1006: setSize is not a function. at
application051_fla::MainTimeline/frame25()[application051_fla.MainTimeline::frame25:7]
I want to make an iPhone application and I want that multiple components working properly in one document.
My little piece of code (don’t think that the problem is in here):
ScrollPane02.source = tekst03;
ScrollPane02.setSize(350,400);
ScrollPane02.move(0, 20);
ScrollPane02.scrollDrag = false;
If you know the answer or what I am doing wrong, please comment! Searching for hours/days!
Thanks in advance!
Uploaded the .fla document. If you want to take a look at it (please), you can download it here: http://www.bregjebouwmans.nl/application061.fla
Edit:
Ok, after digging through the FLA, I finally figured out what you did . . . you right clicked on ScrollPane in the "Library", and clicked "Duplicate". Then you gave it the name ScrollPane02. Except that the duplication process did not connect the new object to the ScrollPane's setup. Instead, it created a generic MovieClip object. Since it is not an actual ScrollPane, it makes sense that all the methods on the timeline's Actionscript will fail.
This is why the solution (in the comments below) works. #AsTheWormTurns just used the first (actual) ScrollPane in two instances on the timeline; is a viable solution.
(The only caveat being that if you change the ScrollPane object in the Library, it will affect all instances. That shouldn't really be a problem, since -- for components -- you generally make changes only to instances.)
Useful tips from my initial answer:
When compiled into an SWF, scenes are just stuck one right after the other in the timeline, just like scenes in a movie. If you do not have a stop() at the end of one scene, it will continue to run right into the next scene, just like a movie. The idea of scenes is to separate content. This means that what exists in sceneA does not exist in sceneB. The scenes also have no access to each other.
My advice is to not use scenes at all. They are difficult to use correctly, and have very little use that is not better done using the timeline or Actionscript.