json – Python arbitrary objects Serialization and Deserialization

I am trying to convert objects inside an object(arbitrary objects) to Json and later retrieve it. I have developed some codes and would like to share if there is any problem in the code.

import json

Here is the first class

class Foo():
    def __init__(self,x,y,bar):
        self.x =x
        self.y = y
        self.bar = bar #Second class object is here

    def toJson(self):
        return json.dumps(Foo(self.x,self.y,self.bar).__dict__)

    @staticmethod
    def fromJson(jsonData):
        data =  json.loads(jsonData)
        return Foo(
            x = data('x'),
            y = data('y'),
            bar = Bar.fromJson(data('bar'))
        )

Here is the second class

class Bar():
    def __init__(self, z):
        self.z = z


    def toJson(self):
        return json.dumps(Bar(self.z).__dict__)

    @staticmethod
    def fromJson(jsonData):
        data =  json.loads(jsonData)
        return Bar(
            z = data('z'),
        )

Convert to Json

jsonData = Foo(100,500,Bar(900).toJson()).toJson()

Retrieve the Json and convert to Object

foo = Foo.fromJson(jsonData)

Print the Object attributes

print(foo.bar.z)

It works actually. But is there any memory leakage? Any security issue?

unity – Making pick up objects, with that have gravity

I am trying to create pickups, that appear after an enemy dies, and that the player can pick up, but I am running into some issues.

First of all, I want the pickups to be affected by gravity, so I need a rigidbody2d and a boxcollider2d (non-trigger), so this works.

enter image description here

Now, if I want to collect the pickups on contact, I need to make the layers for the loot and the player get in contact, so that they can interact.

enter image description here

Now, of course, I do not want to push the pickups around. I want to actually pick them up when I touch them, but the collider is not a trigger so I thought I would use OnCollisionEnter to handle this.

        void OnCollisionEnter2D(Collision2D other)
        {
            var loot = other.gameObject.GetComponent<ILoot>();

            loot?.PickUp(gameObject); // Destroys also the pickup
        }

While this works, I am still using a non-trigger collider, which means that there are some physics effects that are not desired. For instance, when I “jump” onto the pickups.

enter image description here

Notice the subtle, but still present, slowdown in the fall, when the player enters in touch with the pickups?

How could I solve this issue??

Objects Imported from Blender to Unreal have really zoomed Materials

I’ve been learning how to use Blender for UE4. I just started figuring out how to define which sides should have materials on them. In particular, I wanted this building to have different materials for the sides and top. However, when I apply the Materials, they’re very zoomed in.

Zoomed in Texture

At first I thought it was a scale issue, but Unreal supposedly converts the models from FBX units to Unreal units. The scale of the model is exactly the same as the one I made in Blender. And yet, I have this issue.

Since it seemed like a conversion of units issue, I made sure to change Blender to also use centimeters just like Unreal, with no scaling or conversion, and yet the issue still arises. I have tried to find a way to shrink the material, with no luck. It seems the only way to do this would be to copy the texture and modify it, but that seems unnecessary. If I wanted to use the same building with a different material, I’d need to do that over and over again.

Is there something I’m missing when Exporting from Blender and Importing into UE4?

I am using Unreal Engine 2.25.1, and Blender 2.83.1

Thanks for your help!

2d – How can I recreate this gooey effect where objects blend together in unity?

I’m wondering how to recreate this gooey effect that’s possible with html/svg/css as described here.

This only needs to be in 2d and even just for a single color like in the picture for now. I’ve tried setting up a shader that does the blur and the alpha contrast increase as described in the article but the problem is that it’s applied to each object separately so they never blend together.

gooey effect

unity – How can I make some objects to move between waypoints?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Scripting.APIUpdating;

public class Teleporting : MonoBehaviour
{
    public List<GameObject> objectsToTeleport = new List<GameObject>();
    public List<GameObject> teleporters = new List<GameObject>();
    public bool loop = false;

    private int objectstoteleportindex = 0;
    private int teleportersindex = 0;
    private bool startnewcoroutine = false;

    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(Move(3));
    }

    // Update is called once per frame
    void Update()
    {
        if(teleportersindex != teleporters.Count && startnewcoroutine == true)
        {
            StartCoroutine(Move(3));

            startnewcoroutine = false;
        }
        
        if(teleportersindex == teleporters.Count && loop == true)
        {
            teleportersindex = 0;
        }
    }

    IEnumerator Move(int SecondsToWait)
    {
        objectsToTeleport(objectstoteleportindex).transform.position = teleporters(teleportersindex).transform.position;

        yield return new WaitForSeconds(SecondsToWait);

        teleportersindex++;
        startnewcoroutine = true;
    }
}

This is working fine. There is one object to teleport that at the start move to the first teleporter and each 3 seconds he move to the next teleporter.

but now I want to make one more thing :

  • If I have for example 10 objectsToTeleport and not 1 how can I make that the first one like now will move to the first teleporter after 3 seconds when he move to the second teleporter only then send the second objectsToTeleport to the first teleporter and so on so it will make some kind of cycle of the objectsToTeleport moving between the teleporters.

  • and in general if I have for example 10 objectsToTeleport how do I make them all move between the teleporters ? doing it with 1 was easy.

How can I make objects to be teleported between all teleporters?

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class Teleporting : MonoBehaviour
{
    public List<GameObject> teleporters = new List<GameObject>();
    public GameObject() objectsToTeleport;
    public int startingTeleport;
    public float fadeDuration;
    public float dissolveAmount;
    (Range(-3, 3))
    public float range;
    public Vector3 direction;

    private List<Vector3> teleportersPositions = new List<Vector3>();
    private Material material;
    private bool alreadyFading = false;

    // Start is called before the first frame update
    void Start()
    {
        foreach (Transform transform in objectsToTeleport(startingTeleport).transform)
        {
            if (transform.GetComponent<Renderer>() != null &&
                transform.GetComponent<Renderer>().material.shader != null &&
                transform.GetComponent<Renderer>().material.shader.name == "Custom/Teleport")
            {
                material = transform.GetComponent<Renderer>().material;
            }
        }
        var objectToTeleportMaterial = objectsToTeleport(startingTeleport).GetComponent<Material>();


        if (teleporters.Count > 0)
        {
            for (int i = 0; i < teleporters.Count; i++)
            {
                teleportersPositions.Add(teleporters(i).transform.position);
            }
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Teleporting Object")
        {
            StartCoroutine(WaitBeforeGo());
        }
    }

    // Update is called once per frame
    void Update()
    {

    }

    IEnumerator WaitBeforeGo()
    {
        yield return new WaitForSeconds(3);

        if (!alreadyFading) StartCoroutine(Teleport(-3, 3, 5f));
    }

    IEnumerator Teleport(float from, float to, float duration)
    {
        alreadyFading = true;

        var timePassed = 0f;
        while (timePassed < duration)
        {
            timePassed += Time.deltaTime;

            var factor = timePassed / duration;
            var value = Mathf.Lerp(from, to, factor);

            material.SetFloat("_DissolveAmount", value);

            yield return null;
        }

        material.SetFloat("_DissolveAmount", to);

        alreadyFading = false;

        for (int i = 0; i < objectsToTeleport.Length; i++)
        {
            objectsToTeleport(i).transform.position = teleportersPositions(1);
            material.SetVector("_Direction", new Vector4(0, -1, 0, 0));
            if (!alreadyFading) StartCoroutine(Teleport(3, -3, 5f));
        }
    }
}

This part is wrong since alreadyFading is false so it will keep calling Teleport over and over again :

for (int i = 0; i < objectsToTeleport.Length; i++)
            {
                objectsToTeleport(i).transform.position = teleportersPositions(1);
                material.SetVector("_Direction", new Vector4(0, -1, 0, 0));
                if (!alreadyFading) StartCoroutine(Teleport(3, -3, 5f));
            }

Also the directions are wrong.

When getting to the first teleporter the object is fading the direction up and from -3 to 3 :

if (!alreadyFading) StartCoroutine(Teleport(-3, 3, 5f));

but in the next teleporter for example teleportsPositions(1) the direction should be down and from 3 to -3 :

material.SetVector("_Direction", new Vector4(0, -1, 0, 0));
if (!alreadyFading) StartCoroutine(Teleport(3, -3, 5f));

Then teleporting to the next teleporter so now again the direction should be up and the _DissolveAmount should be from -3 to 3 and same for all the teleporters. It should change the direction the _DissolveAmount.

The way I did it in the end of the Teleport Coroutine is wrong I guess.

locking – I can not navigate through the objects in sql server managemente studio – lock never goes away

Whenever I try to navigate through the objects in sql server management studio object explorer I get the error message “Lock request time out period exceeded. (Microsoft SQL Server, error: 1222)”.
It is impossible to list columns in tables, show code of views and procedures, etc.
It’s a SQL Server 2016.
How to look for the cause of this ?
There is a lot of ETL running on the server, can that be the cause ? How to pinpoint the cause ?
enter image description here

How to retrieve values from an array of json objects in PostgreSQL?

I have the following json :

({“transition”:”random_word”,”from”:”paris”,”to”:”porto”,”date”:{“date”:”2020-05-28 11:51:25.201864″,”timezone_type”:3,”timezone”:”Europe/Paris”}},

{“transition”:”rainbow”,”from”:”porto”,”to”:”faro”,”date”:{“date”:”2020-06-06 23:10:06.878539″,”timezone_type”:3,”timezone”:”Europe/Paris”}},

{“transition”:”banana”,”from”:”faro”,”to”:”rio_de_janeiro”,”date”:{“date”:”2020-06-06 23:14:10.975099″,”timezone_type”:3,”timezone”:”Europe/Paris”}},

{“transition”:”hello”,”from”:”rio_de_janeiro”,”to”:”buenos_aires”,”date”:{“date”:”2020-06-06 23:14:15.314370″,”timezone_type”:3,”timezone”:”Europe/Paris”}})

Imagine I want to retrieve the last stop of my traveler (the value of the key “to” from the last json object. Here : buenos_aires) and the date (here :2020-06-06 23:14:15.314370).

How should I proceed knowing that I want to do that using PostgreSQL ?

Thank you a lot for your help !

Map two input streams, one graphics objects and the other characters through Show

The question is how to sequentially execute Show with two streams of input. The first is graphics object stream and the second is a character stream for supplying labelling for the graphics. I tried

ss={{ListPlot(x1)},{ListPlot(x2),…};labelling={aa,bb,cc,dd….}; Map(Show(#1,PlotLabel->StringJoin(#2,”…”,”…”))&,{ss,labelling})

I tried both Map and MapThread to inconsistent results, i.e., works sometimes and not work some other times. It became consistent when I put the labelling elements into individual curly brackets, i.e., labelling={{aa},{bb},{cc},(dd)) Wonder why is this the case?

physics – How to search through large numbers of discrete objects that interact with each other, like Minecraft blocks?

Imagine you had a world like Minecraft, but wanted to bake in some sort of physics (okay, I was playing minetest actually).

For example, blocks under too much pressure might break, limiting how many blocks can be stacked on top of one another. I see one approach to this:

  1. Systematically check each block. See if there is a block on top of that, a block on top of that, ect. Then, determine the pressure on the block that you just started with. Do this for each and every block.

I also imagine you could somehow check each block, then have it modify the properties of the blocks around it. If all force was from top to bottom, you could just start at the top. But if you want to have a “net force” (so unsupported blocks accelerate) I have no idea how this could be implemented. For instance, three blocks are floating in mid air.

How can I solve this class of problem?