How to pass Unreal Engine 4 Niagara Int Array to Blueprint - unreal-engine4

I am struggling to retrieve a Niagara Int Array from a Blueprint. While researching this topic, I came across the "Niagara Get Int32 Array" Node, but it is not working as expected. For some reason, I only get a valid Array returned when I try and retrieve a User exposed Parameter, but when I try and get a System or Emitter Array, it does not return a valid array.
This returns Length 0 (4 is expected)
This returns Length 4 ( as expected)
My Question is it possible to retrieve System or Emitter Arrays from Niagara Systems and pass them to a blueprint? Am I using this Node correctly? Or should I be doing this with a 2D grid and a Texture which is interpreted in a shader later?
Any help is appreciated

You can use one of these two data interfaces:
The Export data interface can send an array of particle data to a blueprint (there is an example system using this in the Niagara_Advanced map of the content examples)
The Array data interface can be used to send an array from blueprint to Niagara or between emitters.

Export Particle Data interface is super limited and also does not deliver persistent particle indices over multiple frames. Additionally, it only allows to output two vectors and a scalar parameter, not an array or list of values.
It turns out that it is not possible to retrieve an array from a Niagara GPU emitter. The solution was to use Grid Collections instead of arrays and output those as Render Target Textures that would encode the desired information. These textures can then be interpreted by a custom compute shader or via a blueprint ( this is only advisable if you are going to code your own ReadRenderTargetPixel function, since the native one blocks the render thread)

Related

Is it possible to use graph-on-parent with [clone]d abstractions in some way?

I know you can open an abstraction with the vis message, but I haven't found a way to present my abstractions in the patch containing the clone object. Perhaps dynamic patching is the only way to achieve this? I have searched the pd forum, mailing list and Facebook group without success.
Currently (as pd 0.48-1) there is no way of making the [clone] read the GOP of it's contents.
As a workaround you can encapsulate the [clone] object into an abstraction that provides a GUI that displays information about the selected clonede instance.
For example, let's say you have a Object called [HarmonicSeries] that, given an fundamental, it uses a [clone] object to create 8 instances of [Harmonic], each one containing a osc~ of the desired frequency. And you want to display the frequency of each Harmonic. Instead of using GOP on [Harmonic] you would use GOP on [HarmonicSeries] and provide an Interface to selected the desired harmonic to collect information.
The [harmonic] abstraction: it expects two parameters:
The fundamental frequency
The index of the harmonic
Then it multiplies both to get the harmonic's frequency and store it on an [float]. When it receives a bang it then outputs that frequency to it's left outlet.
[
Let's [clone] it and wrap it into the [HarmonicSeries] abstraction.
When the user clicks on the [hradio] to select the desired harmonic it sends a bang message to the correct harmonic, which in turn sends the stored frequency to it's outlet. It then displays the harmonic's index and the harmonic's frequency in number boxes.
Here's an example of it working (in the [HarmonicSeries-help] object)
This is a simple example but the principle is the same with complex cases. You encapsulate the [clone] into an abstraction that provides an interface for reading data from the cloned instances.

What should be in a model

I am struggling with the question of what belongs in the Model in a MVVM architecture. Suppose I have an object called a Line which is made up of x,y data point pairs. I want to be able to add points to the line and I want to be able to do interpolation of points. For instance, I want to return a vector of y values when the user passes in a vector of x values. In order to do the interpolation I need the points in the Line object to be sorted in ascending x. Should the model just be the collection of Points? Does the model handle the sorting and interpolation or should a service handle this?
What should be in a model?
Short answer: The data
Longer answer:
The model represents the part of the application that is dedicated to data storage. So database access goes in the model. A good represention of that is a Repository-Pattern. (Which, in a more rigid interpretation of MVVM belongs to the service layer).
Your ViewModel holds the dynamic data. This means selection, ordering, locales, and so on.
A very good start on MVVM (and MVVM in action) is this video by Jason Dolinger. The sourcecode of the example can be found here
It is just one hour long, but i covers very good the aspects of MVVM and why it is that successful.

glDrawElements vs glDrawArray efficiency

I'm making a game for iOS and Android.
I've seen in a lot of places that drawing using indices is more efficient than just drawing triangles array.
The thing is that i'm using lossy compressed vertices (like the md2's file format) and it takes less than just the indices alone -
Array: N * 3 (xyz) * 1 (uchar) + translate (12 bytes) + scale (12 bytes).
Element: N * 3 (xyz) * 4 (uint) + Array / ~10
It seems like the array is even better choice than indexed and compressed element, altough apple' s OpenGL profiler tool says that I should use glDrawElements..
Does the OpenGL implementation prefer indexed array? or it's because that the indexed array contains less data than the regular uncompressed array?
p.s.
I'm using OpenGL es 2.0 and the vertex shader is the one who decompresses the vertices.
Are you using Vertex Arrays or Vertex Buffer Objects? If you are using Vertex Arrays, then you might want to consider looking into glDrawRangeElements rather than glDrawElements.
Unless all of your polys have distinct vertices (pretty unlikely), glDrawElements will be faster than glDrawArray because glDrawElements will take advantage of the fact that repeated vertices will be loaded into the gpu cache, and will not have to be loaded more than once for each poly that that vertex is a part of. However, with glDrawArray, it will iterate through the array and not be able to associate similar vertices, so it will have to load them multiple times.
However, it always depends on your specific situation. Try using a profiler or getting a framerate using each of these methods. It shouldn't be too hard to switch between them. If one is clearly better, use that one. If neither is outstandingly better, then it probably doesn't matter too much.
Remember, premature optimization is the root of all evil. Good luck! :)
Using glDrawElements() will save a substantial amount of memory and you can specify the array elements in any order.
Using glDrawArrays(), however, your only option is to iterate sequentially over the list.
You have to experiment.

Storing characters in MATLAB arrays

I want to store a character along with numbers ? Is using Cells the only way ?
Yes, unless you store the ASCII values but I don't think it would be very useful.
Edit: Or an array of structures?
a.num = [1 2 3]
a.char = 'A'
I don't know exactly what you are trying to achieve…
This is a classic Computer Science 101 sort of question. An array holds 1 type of data traditionally. In matlab the term gets abused.
Here are some things to know:
An array of characters is called a string
An array can only store one data type
The size of an array can’t change
But matlab has an abstraction on top of all this so the engineer that didn't study programming for a year can still get the job done. Whilst matlab lets you change the size of a 1D matrix, it still won't let you have different types of data in the same array. Keep in mind that matlab 1D arrays aren't strictly arrays because this fact. Similarly with arrays of arrays with differing in size. Matlab doesn’t allow different data structures for optimization reasons.
This question arises from not knowing the containers which are available.
List: A container indexed elements (great for sorting and adding elements quickly)
Set: for a collection of unique elements (great for ensuring that there are no duplicates)
Map: Great for quickly retrieving elements based on a unique identifier
Java has implementations for these and you can use these within matlab if you want which is the general way it is done if you need a collection other than a matrix. I don’t think matlab bothered to wrap these classes themselves because they would be exactly the same anway.
In general its not a great idea to store different data types in these collections if you can avoid it, do so but otherwise so be it.
PS I don't think structs should ever be used because there is no way to know what members they have without debugging them.
If you do
a.num = [1 2 3]
a.char = 'A'
Unless you tell everyone a.num and a.char exist there is no way of knowing that a has char and num, without running code. Bad bad practice.

How can I randomly draw from an NSMutableArray and not use the same number twice?

For a game I am making, I am passing an array of objects of a set number that I am going to have the user identify. I would like to make the presentation of these objects random. But I also need to make it so that the same object isn't presented twice.
So this is the solution I have thought of tentatively: I pass in an array of objects to my game controller, of size 10. In the game controller I create a random number between 0-9 and then pull from the array with that number as the index...I don't know if that will work though because I need to make sure that the same random number isn't used in a game session.
Any thoughts on how I might accomplish this type of random game logic?
Thanks
You should look for a shuffling algorithm and shuffle your array contents.
This way you can just pop numbers off the array without worrying if they've been used before - when you get to the last number, reshuffle the array and repeat.
Here's an example: http://www.cocoanetics.com/2009/04/shuffling-an-nsarray/
To avoid having the same index come up more than once I'd remove the object from the array each time. If you base the random number of the size of the array you should be fine. Make a copy of the array if you want to be able to re-create it to start over again.