How to spawn objects (boxes) with a certain logic in Unreal Engine 4 WITHOUT blueprints? - game-development

I am new to ue4, so the question may be easy or have a tutorial that I couldn't find:)
I have a world in ue4 (imported) which is static. I want to add some boxes (with different pictures on each) which will spawn/despawn from the world at certain times and locations. How would I do that in a project without blueprints? A link to a tutorial or an explanation would be very much appreciated.
In addition, I would like some of the boxes to move in a simple "patrol". In this too, any help would be appreciated

To spawn an actor, just call SpawnActor method
auto myActor = GetWorld()->SpawnActor<MyActorType>(MyActorType::StaticClass(), location, rotation, spawnParameters);
It returns a pointer to the spawned entity: if you want to update it, just keep it and then at every tick set a new position/orientation
myActor->SetActorLocationAndRotation(
newPosition,
newOrientation,
false,
nullptr,
ETeleportType::None
);

Related

Is there a way to change an object's material dynamically using Script / Patch editor? - Spark AR / Reactive Javascript

If it's okay, I'm kind of in need of assistance,
This is an AR filter mini game.
I would like to replace an object's material when the loop count reaches a certain value. I found it extremely challenging to do it with the Patch Editor so I went and explore options with scripting but I really hit a wall with Reactive Javascript. (I'm only an amateur with the conventional javascript and have no idea how to use If-Else statements in Reactive JS).
So I was wondering if there's a way to change an object's material dynamically, controlled by a loop counter? Any help would be greatly appreciated.
Let me know if there are any additional screenshots you need (Or project file, for the matter).
The object does not have a material attached to it.
(The software uses reactive javascript)
*I also shared a similar post in the Facebook group dedicated to Spark AR but I don't seem to get any responses so I figured I'll try my luck here.
Someone from the Facebook group responded and told me that a loop is sequential and a callback is reactive and provided the callback function sample code and I slotted my conditional statement in and it worked! Just thought I'll post this answer here.
const Time = require('Time');
const interval = Time.setInterval(function changeMat(){
if (loopCountNum.pinLastValue() >= 0 && loopCountNum.pinLastValue() <=10)
{
car.material = carMaterial;
}
else if (loopCountNum.pinLastValue() >= 11)
{
car.material = carMaterial2;
}
}, 500);

videojs-thumbnails plugin shows thumbnails at incorrect time

I'm trying to use "videojs-thumbnails" plugin from https://github.com/brightcove/videojs-thumbnails and noticed that thumbnail's time, specified in the plugin configuration is not matching the timestamp in the seek bar. Coming across different comments regarding this issue I found suggestion at https://github.com/brightcove/videojs-thumbnails/issues/43 to replace line
mouseTime = Math.floor((left - progressControl.el().offsetLeft) / progressControl.width() * duration);
to
mouseTime = Math.floor((left) / progressControl.width() * duration);
By removing
- progressControl.el().offsetLeft
However, that produces still not exact time match.
Finally I came with redefined value for the
var left
Getting it from the current value of
.vjs-mouse-display
So, my final codes are:
left=parseInt((document.querySelector('.vjs-mouse-display').style.left),10);
mouseTime = Math.floor((left) / progressControl.width() * duration);
Now everything works correctly.
Greatly appreciate for comments/suggestions.
This is NOT an answer to your specific question / issue, but rather, an alternative implentation approach.
I, too, wanted thumbnails for my video(s), so I proto-typed a page
that used videoJS's plugin. I don't recall all the details of the
issues that I ran into trying to use that plugin, but I finally decided
to abandon the plugin, and design an alternative, which has its own
separate 'slider' just above the viewer. [ One 'drags' my slider,
(rather than hover along it, as you do on YouTube's videos), so that it
can work straight-forwardly on touch-screens...i.e. on Android, etc. ]
And, rather than try to extract images from the video in real-time,
(See: How to generate video preview thumbnails for use in VideoJS? ), I chose to prepare the images, ahead of time, using 'ffmpeg' and the cmd-line interface to 'ImageMagick'.
Details of that part are here:
http://weasel.firmfriends.us/GeeksHomePages/subj-video-and-audio.html#implementing-video-thumbnails
My 'proof-of-concept' webpage based on that approach is here:
https://weasel.firmfriends.us/Private3-BB/
I hope this is helpful.

Elm project scaling: separating Messages/Updates

I am trying to separate files in an Elm project, as keeping everything in global Model, Messages, etc. would be just a mess.
Here is how I tried it so far:
So, there are some global files, and then Header has its own files. However I keep getting error, when importing Header.View into my global View:
The 1st and 2nd entries in this list are different types of values.
Which kind of makes sense:
The 1st entry has this type:
Html Header.Messages.Msg
But the 2nd is:
Html Msg
So, my question is whether all the messages (from all my modules, like Header) needs to be combined somehow in global Messages.elm? Or there is a better way of doing this?
My advice would be to keep messages and update in 1 file until that feels uncomfortable (for you to decide how many lines of code that means - see Evan's Elm Europe talk for more on the modules flow). When you want to break something out, define a new message in Main
type Msg
= HeaderMsg Header.Msg
| ....
Then use Cmd.map HeaderMsg in your update function and Html.map HeaderMsg in your view function to connect up your sub-components

cytoscape.js successors and predecessors

I'm looking to select the successors and the predecessors from a selected node within my graph. Essentially what I need my code to do is select the full path in and out of a note right to the end nodes.
I know how to select one or the other (successors or predecessors) but not both,
i'm currently using :
var nhood = node.successors();
cy.batch(function(){
cy.elements().not( nhood ).removeClass('highlighted').addClass('faded');
nhood.removeClass('faded').addClass('highlighted');
I'm very new to JS and I'm pretty much fumbling around in the dark just now, learning as I go, so please excuse me if this is a simple question.
Thanks.
You look like you want a BFS instead, because you want the entire connected component essentially. See http://js.cytoscape.org/#collection/algorithms/eles.breadthFirstSearch
You can keep an array and put visited nodes into them.

PsychoPy Builder - How to I take a rest part way through a set of trials?

In PsychoPy builder, I have a lot of trials and I want to let the participant take a rest/break part way through and then press SPACE to continue when they're ready.
Any suggestions about how best to do this?
PsychoPy Builder uses the TrialHandler class and you can make use of its attributes to do control when you want to take a rest.
Assuming you're trial loop is utilising an Excel/csv file to get the trial data then make use of trialHandler's attribute : thisTrialN
e.g.
1/ Add a routine containing a text component into your loop (probably at the beginning) with your 'now take a rest...' message and a keyboard component to take the response when they are ready to continue.
2/ Add a custom code component as well and place something similar to this code into its "Begin Routine" tab:
if trials.thisTrialN not in [ int(trials.nTotal / 2) ]:
continueRoutine=False
where 'trials' is the 'name' of your trial loop.
The above will put a rest in the middle of the current set of trials but you could replace it with something like this
if trials.thisTrialN not in [10,20]:
continueRoutine=False
if you wanted to stop after 10 and again after 20 trials.
Note, if you're NOT using an Excel file but are simply using the 'repeat' feature of a simple trial loop, then you'll need to replace thisTrialN with thisRepN
If you're using an Excel file AND reps you'll need to factor in both when working out when you want to rest.
This works by using one of Builder's own variables - continueRoutine and sets it false for most trials so that most of the time it doesn't display the 'take a rest' message.
If you want to understand more, then use the 'compile script' button (or F5) and take a look at the python code that Builder generates for you.